Search code examples
videolockingmpmovieplayercontrollerbackground-process

How can I keep a MPMoviePlayerController from dismissing on lock button press?


I am attempting to play the sound from a video while the iphone screen is locked. Can I keep the MPMoviePlayerController from being dismissed by a lock screen press? If not I plan to subclass a MPMoviePlayerController and prevent it from being dismissed by a lock button press, which method will allow me to do this?


Solution

  • After toying with a thousand other things I found what I needed to do.

    All I needed to do was make two adjustments:

    1. Add this to the AppDelegate.m in the application: didFinishLaunchingWithOptions: method:

      NSError *error = nil;
      
      BOOL success = [[AVAudioSession sharedInstance]
                  setCategory: AVAudioSessionCategoryPlayback
                  error: &error];
      
      if (success == false) { /* handle error */ }
      
    2. Add the following to your info.plist after you drag it into a text editor like Sublime:

      <key>UIBackgroundModes</key>
      <array>
              <string>audio</string>
      </array>
      

    If you setup your video correctly you will be able to listen to the audio from the video while using other apps and while the screen is in sleep mode.