1

我正在尝试让 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。
  • 如果我打开镜像并将视图推送到第二个屏幕,它会起作用
  • 如果没有视频播放,声音会起作用。

参考资料: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

4

1 回答 1

0

我有同样的问题,我疯了好几个小时才找到答案!

将此设置为NO

[_currentPlayer setAllowsExternalPlayback:NO];

并删除此行

[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];

它会起作用的!

于 2020-04-10T20:43:55.300 回答