MPMoviePlayerController multitasking problem

2019-02-14 14:45发布

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

3条回答
Bombasti
2楼-- · 2019-02-14 15:15

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

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
查看更多
祖国的老花朵
3楼-- · 2019-02-14 15:24

may be you forget to add this in

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
   }
查看更多
ゆ 、 Hurt°
4楼-- · 2019-02-14 15:32

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)
查看更多
登录 后发表回答