Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>These are the codes for the requested actions, appSoundPlayer is a property of AVAudioPlayer declared in h file. Also this example plays a song in the resource folder.</p> <pre><code>#pragma mark - #pragma mark *play* - (IBAction) playaction { NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"songname" ofType:@"mp3"]; NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; self.soundFileURL = newURL; [newURL release]; [[AVAudioSession sharedInstance] setDelegate: self]; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil]; // Registers the audio route change listener callback function AudioSessionAddPropertyListener ( kAudioSessionProperty_AudioRouteChange, audioRouteChangeListenerCallback, self ); // Activates the audio session. NSError *activationError = nil; [[AVAudioSession sharedInstance] setActive: YES error: &amp;activationError]; AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil]; self.appSoundPlayer = newPlayer; [newPlayer release]; [appSoundPlayer prepareToPlay]; [appSoundPlayer setVolume: 1.0]; [appSoundPlayer setDelegate: self]; [appSoundPlayer play]; [stopbutton setEnabled:YES]; [playbutton setEnabled: NO]; playbutton.hidden=YES; pausebutton.hidden =NO; }//playbutton touch up inside #pragma mark - #pragma mark *pause* -(IBAction)pauseaction { [appSoundPlayer pause]; pausebutton.hidden = YES; resumebutton.hidden = NO; }//pausebutton touch up inside #pragma mark - #pragma mark *resume* -(IBAction)resumeaction{ [appSoundPlayer prepareToPlay]; [appSoundPlayer setVolume:1.0]; [appSoundPlayer setDelegate: self]; [appSoundPlayer play]; playbutton.hidden=YES; resumebutton.hidden =YES; pausebutton.hidden = NO; }//resumebutton touch up inside #pragma mark - #pragma mark *stop* -(IBAction)stopaction{ [appSoundPlayer stop]; [playbutton setEnabled:YES]; [stopbutton setEnabled:NO]; playbutton.hidden=NO; resumebutton.hidden =YES; pausebutton.hidden = YES; }//stopbutton touch up inside </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload