4

I develop an application on iphone that uses MPMoviePlayerController to play audio file. When Application goes to background, if mpmovieplayer is playing, iphone continues to play the current music, but when it ends, the next track doesn't start.

I try to start the next audio file in the MPMoviePlayerPlaybackDidFinishNotification and when I follow the code using the debugger I can see that the method is invoked and the code executed, bat the next audio file still doesn't start.

Is this possible on iOS 4.1 or this is a limitation?

Best regards Samantha

Samantha
  • 41
  • 1
  • 2

3 Answers3

2

You should read the Technical Q&A QA1668: How to play audio in the background with MPMoviePlayerController.

Summary of the steps needed:

  • declare that your application supports background execution for audio
  • assign an appropriate category to your audio session (default category is not ok)
Guillaume
  • 21,685
  • 6
  • 63
  • 95
  • Thank you for your reply, but I already know that Q&A and I can actually play a media file when the app is in background. My problem arises when The file ends and I need to play another one without returning to the application. – Samantha Nov 19 '10 at 12:55
  • Could you give more details about what you have done. Maybe some code? That would help reduce the search. – Guillaume Nov 19 '10 at 15:55
  • @Samantha:Did you get the solution for this issue.Please post the solution if yes as I am also facing the same thing – Yogi May 23 '12 at 07:43
  • Looks like @Yogi found this worked for him: http://stackoverflow.com/questions/10715250/mpmovieplayercontroller-doesnt-play-next-url-when-in-background/11380927#11380927 – Steve Moser Aug 13 '12 at 18:17
  • @Samantha: Yes. I used AudioStreamer by Matt Gallagher and it solved the problem for me. I had to do some changes in the code to make it perfect for my need but those were not very major changes. – Yogi Aug 17 '12 at 05:33
2

I got it working by putting following two lines in Delegate file:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
  • Note that this doesn't appear to work on the simulator, but on the device it works - confused me. – Andrew Jul 07 '12 at 04:19
  • Brilliant, thanks! Just put the lines in your play Method, import AVFoundation, and there you go. – brainray Oct 18 '13 at 18:41
0

may be you forget to add this in

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
   }
Banker Mittal
  • 1,918
  • 14
  • 26