如何使AVPlayer与AirPlay一起使用而不进行镜像?

问题描述 投票:1回答: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

avfoundation avplayer airplay apple-tv
1个回答
0
投票

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

将此设置为NO

[_currentPlayer setAllowsExternalPlayback:NO];

并删除此行

[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];

它将起作用!

© www.soinside.com 2019 - 2024. All rights reserved.