我正在尝试让AVPlayer使用AirPlay在AppleTV上播放。看起来很简单,并且根据Apple文档,应该支持它。
这里是代码:
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];
[我注意到的一件事是,当我打开AirPlay时,播放器的时间似乎并没有向前移动,有时我认为它实际上跳了一两秒。
有什么想法吗?
旁注:
我遇到了同样的问题,我一直疯了几个小时,直到找到答案!
将此设置为NO
[_currentPlayer setAllowsExternalPlayback:NO];
并删除此行
[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];
它将起作用!