2

I have iOS application that plays video through HTTP via AVPlayer.

I have MPVolumeView that allows to select airplay device to stream current playback to.

But now I need to have ability to programmatically stop video streaming, and continue playback on AVPlayer's video layer in my application on iPad screen. (Like MPVolumeView's button does, but programmatically)

Please, help me, I tried to find solution myself and with the help of google but I am not able to solve this problem:(

Is it really possible?

Thanks!

Alexander Tkachenko
  • 3,221
  • 1
  • 33
  • 47

2 Answers2

4

In this scenario, you don't need to program multiple displays directly. You just need to tell iOS' video subsystem to stop using the other display...

AVPlayer has a property allowsExternalPlayback which you can set to NO. This will disable playback on the external display. Playback will continue on the player's original AVPlayerLayer within your application.

spinosa
  • 61
  • 5
  • 1
    I've tried this, video playback is disabled on external display and continues to play in iPad screen, but audio still plays via external display – Alexander Tkachenko Aug 09 '13 at 11:04
  • Yup... I also encounter this issue. The audio still plays via the external display. Did you find a solution for this? @AlexanderTkachenko – KarenAnne Jul 08 '16 at 01:51
  • @KarenAnne Unfortunately no. I have some thoughts that 'video' playback via AVPlayer uses AVAudioSession to play sound, so when we disable allowsExternalPlayback, AVAudioSession uses it's own settings and continuous to play via external device. I think maybe it's also needed to configure AVAudioSession to disable airplay. – Alexander Tkachenko Jul 08 '16 at 08:53
  • Did someone of you found a solution for this? I'm having the same issue that the audio keeps playing via the external display... thx! – adams.s Sep 22 '20 at 22:49
1

First you'd have to read this reference on programming multiple displays.

But in this specific situation I think, you are looking for [UIScreen screens] which returns an NSArray of UIScreen objects. The UIScreen with index 0 is the internal display and the one with the index 1 is the Apple TV's display. From now on, according to this documentation and its examples you only need to create a UIWindow which has the screen property of the UIScreen you want to display on. Then you can easily add layers, views, etc. to that UIWindow.

Rickye
  • 1,023
  • 1
  • 9
  • 16
  • Thanks for references and help Rickye, It seems to be a key for solution, I'll try to use it and maybe it will solve my problem. It's definitely worth researching! – Alexander Tkachenko Jun 26 '13 at 20:06