Pages

Wednesday, March 27, 2013

Stop and Resume audio from other view controller iOS AVPlayer

I have an app that plays sound when it loads. This happens in the AppDelegate.m file because the audio is used in most places. But I would like to pause the sound when the user clicks on the help menu because the help menu contains a help video and I do not want the sound to interfere. And when the user goes back to the main menu I want the sound to resume. Basically I would like to access the sound and perform things on it. How can I do this.

Thanks in advance!

 

AppDelegate.m:

- (void)applicationDidBecomeActive:(UIApplication *)application

{

      

   NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/AppMusic.mp3", [[NSBundle mainBundle] resourcePath]]];

 

          NSError *error;

  audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

  audioPlayer.numberOfLoops = INFINITY;

 

          [audioPlayer play];

   

}


View the original article here

0 comments:

Post a Comment