avfoundation - 如何让AVPlayer在不镜像的情况下与AirPlay一起使用?

标签 avfoundation avplayer airplay apple-tv

我正在尝试使用 AirPlay 让 AVPlayer 在 AppleTV 上播放。这看起来很简单,根据苹果文档,它应该受到支持。

代码如下:

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

引用文献: 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

最佳答案

我也遇到了同样的问题,我疯狂了好几个小时,直到找到答案!

将其设置为NO

[_currentPlayer setAllowsExternalPlayback:NO];

并删除此行

[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];

它会起作用的!

关于avfoundation - 如何让AVPlayer在不镜像的情况下与AirPlay一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18176703/

相关文章:

iphone - 在电影之间切换时 AirPlay 闪烁

objective-c - 何时释放CMBlockBufferRef?

ios - AVAudioSession 和 AirPods

iOS7+ Image Picking 的最佳实践是什么 (>2014)

ios - 无法使用 airplay (Apple TV) 将自定义 View 推送到外部显示器

iOS 将 MPMoviePlayerController 镜像到电视,全屏播放电视屏幕

ios - 录制 iOS 时更改视频的最大持续时间

ios - 如何从视频流中生成缩略图?

ios - 在 AVFoundation AVSampleBufferDisplayLayer 中循环播放视频

swift - 如何从 Swift 中的本地视频文件中获取帧?