Question

I have multiple videos being played from my iphone app and when I use airplay to view it, it shows up fine. I want to be able to turn off the iphone in order to not waste battery etc.

How can I use airplay with video while the iphone is in sleep-mode/locked?

Was it helpful?

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 and use airplay while iphone is in sleep mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top