6

When streaming a video from an iPhone (or any iOS device) to a TV via Airplay, the stream stops as soon as the device goes to sleep from inactivity. At the moment, I disabled the sleep timer so that the device does not automatically sleep, but is there a better solution to this?

Is setting AVPlayer.externalPlaybackActive enough to allow the OS to know to keep playing when the screen is off? If not, is there an alternate way to keep Airplay running even if the device turns off its screen?

PaulG
  • 13,871
  • 9
  • 56
  • 78
aeonsamurai
  • 69
  • 1
  • 1
  • 2

2 Answers2

4

To continue airplay playback, add "App plays audio" to the "Required background modes" in the AppName-info.plist

AppName-info.plist

and set the audio session like:

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
YoonHo
  • 1,046
  • 9
  • 10
  • 1
    This will get you rejected if you are trying to prevent screen-locking while AirPlay for videos is active. This is a quote from such rejection notice: `We noticed your app declares support for audio in the UIBackgroundModes key in your Info.plist, but no audible content is played when the application is in the background. While your intention may have been to provide this functionality, at the time of review, we were not able to play background audio for your app.` – Till Mar 04 '13 at 20:15
  • This is not for preventing screen-locking. It's to stream video (or audio) through AirPlay during the device is locked. The audible content (and/or visible contents) is played on the AirPlay enabled device, and I don't think this is the case for rejection. Mine was approved with no problem with this. Of course, some people used this (with silent audio) to make their apps running in background, and as far as I know, this is the case. – YoonHo Apr 03 '13 at 20:54
0

To Fix this issue go to Settings > General > AirPlay & Handoff > Automatically AirPlay to TVs > Change it to Never.