4

I have an app that plays several webvideos like Youtube and Vimeo in a UIWebView. When the video plays it is possible to send it to an Apple TV over AirPlay.

Currently, during playback over AirPlay the video stops when I pause the app and move it to the background.

My desired result is that the video will keep playing on the Apple TV.

After some research I found out that I have to set the Required background modes in the Info.plist to App plays audio. Unfortunately this did not work.

So what does need to be set to keep the video playing over AirPlay when the app is moved to the background.

Wienke Giezeman
  • 159
  • 2
  • 17
  • i simply set `webView.mediaPlaybackAllowsAirPlay = YES;` and `Required background modes` to YES, and it works. is there anything you did differently? – BabyPanda Nov 27 '12 at 08:51
  • I put mediaPlaybackAllowsAirPlay to yes and set Required background modes to App plays audio. But still when I put the app to the background it stops playing. – Wienke Giezeman Dec 03 '12 at 20:50
  • Ok I tested it on iOS 5 now and that worked like described above. For iOS 6 doesn't work. Does iOS 6 require more other settings? – Wienke Giezeman Dec 07 '12 at 09:10
  • I've only tested the method on iOS6 and it worked. But it seems to mess with UIWebView, maybe you can check [Required background modes iOS6 Xcode 4.5](http://stackoverflow.com/questions/12603294/required-background-modes-ios6-xcode-4-5) which refers to [this](http://stackoverflow.com/questions/11616001/uiwebview-html5-audio-pauses-in-ios-6-when-app-enters-background/12414719) – BabyPanda Dec 07 '12 at 09:17

1 Answers1

6

i've tested this on iOS6 with UIWebView loading video webpage, and it does the job. the audio session needed to be set as AVAudioSessionCategoryPlayback in order to be played in background.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
Community
  • 1
  • 1
BabyPanda
  • 1,562
  • 12
  • 18
  • Thanks! Setting the audio session category to `AVAudioSessionCategoryPlayback` is all that is necessary, to make AirPlay work properly from a video inside a `UIWebView`. The video continues to play on Airplay even after the device goes to sleep. The `mediaPlaybackAllowsAirPlay` property is YES by default. – Dhiraj Gupta May 24 '13 at 09:17