我试图让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时,玩家的时间似乎没有向前移动,有时我认为它实际上会跳回一两秒钟 .

有任何想法吗?

Side Notes:

  • 使用AVFoundation构建合成,视频格式为H.264 .

  • 如果我打开镜像并将视图推到第二个屏幕,它会起作用

  • 如果没有视频播放,声音会起作用 .

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