Artilheiro
Artilheiro

Reputation: 4005

How to make AVPlayer work with AirPlay without mirroring?

I am trying to get AVPlayer to play on an AppleTV using AirPlay. It seems simple and according to Apple docs it should be supported.

Here's the code:

AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:_composition];
playerItem.audioMix = _audioMix;
playerItem.videoComposition = _videoComposition;

_currentPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[_currentPlayer setAllowsExternalPlayback:YES];
[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];
[_currentPlayer setAllowsAirPlayVideo:YES];
[_currentPlayer setUsesAirPlayVideoWhileAirPlayScreenIsActive:YES];
[_currentPlayer addObserver:self forKeyPath:@"rate" options:0 context:nil];
[_currentPlayer addObserver:self forKeyPath:@"externalPlaybackActive" options:0 context:nil];

One thing I noticed is that the player time doesn't seem to move forward when I turn on AirPlay and sometimes I think it actually jumps back a second or two.

Any ideas?

Side Notes:

References: http://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AirPlayGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011045-CH1-SW1

http://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009530

Upvotes: 2

Views: 6120

Answers (1)

Ahmed Fathi
Ahmed Fathi

Reputation: 238

I had the same issue, I was going crazy for hours till I found it the answer!

Set this to NO

[_currentPlayer setAllowsExternalPlayback:NO];

and remove this line

[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];

It will work!

Upvotes: 2

Related Questions