Search code examples
objective-cmpmovieplayercontroller

Keep video playing when app goes to the background


In my application, a user is able to watch a video. I want to have it so that when they push the home button or whenever the app goes to the background while the video is playing, I want it to continue to play so they can continue to hear the audio.

iTunes University does exactly what I'm trying to do.

I am currently using the MPMoviePlayerViewController when it comes to playing videos.

I've spent some time researching and trying various potential solutions such as trying to remove the observer like so

[[NSNotificationCenter defaultCenter] removeObserver:player name:UIApplicationDidEnterBackgroundNotification object:nil];

I've also configured my app capabilities to allow this sort of background functionality.

However, the video always stops playing when the user sends the app to the background.


Solution

  • This should be possible with the current version of the SDK as long as you configure your background modes correctly. Check out this guide from Apple which outlines the exact steps you will need to take.

    https://developer.apple.com/library/ios/qa/qa1668/_index.html

    Make sure you take a special look at the "Special Considerations for Video Media" section of this guide.

    I hope this helps!

    Cheers