Reputation: 4005
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:
Upvotes: 2
Views: 6120
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