Как заставить AVPlayer работать с AirPlay без зеркалирования?

Я пытаюсь заставить AVPlayer играть на AppleTV с помощью AirPlay. Это кажется простым и, согласно документам 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


person Artilheiro    schedule 11.08.2013    source источник
comment
Похоже, есть ошибка с использованием AVComposition и AirPlay: openradar.appspot.com/14275139   -  person Artilheiro    schedule 13.08.2013


Ответы (1)


У меня была такая же проблема, я часами сходил с ума, пока не нашел ответ!

Установите это на NO

[_currentPlayer setAllowsExternalPlayback:NO];

и удалите эту строку

[_currentPlayer setUsesExternalPlaybackWhileExternalScreenIsActive:YES];

Это будет работать!

person Ahmed Fathi    schedule 10.04.2020