我正在尝试让 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 时,播放器时间似乎没有向前移动,有时我认为它实际上会向后跳一两秒。
有任何想法吗?
旁注:
- 该合成使用 AVFoundation 构建,视频格式为 H.264。
- 如果我打开镜像并将视图推送到第二个屏幕,它会起作用
- 如果没有视频播放,声音会起作用。