简体   繁体   English

重新初始化AVQueuePlayer,而无需创建新的AVPlayerLayer

[英]Reinitializing AVQueuePlayer without haing to create new AVPlayerLayer

while playing remote HLS videos, I am re-initializing AVQueue player which is already initialized with items by using 在播放远程HLS视频时,我正在重新初始化AVQueue播放器,该播放器已经通过使用进行了项目初始化

(AVQueuePlayer *)initWithItems:(NSArray<AVPlayerItem *> *)items

However, by doing this sound plays in background but the AVPlayerLayer is stuck at the last frame of the previous video, the video does not update. 但是,通过这样做,声音会在后台播放,但AVPlayerLayer停留在上一个视频的最后一帧,则视频不会更新。 In order to make sure that video gets updated, I need to remove the previous layer for UIView of video player, re-create the new AVPlayerLayer and assign it to the UIView for player using following : 为了确保视频得到更新,我需要删除视频播放器的UIView的上一层,重新创建新的AVPlayerLayer并将其分配给播放器的UIView,方法如下:

[oldAVPlayerLayer removeFromSuperLayer]
[newAVPlayerLayer playerLayerWithPlayer: myAVQueuePlayer]
[myViewForPlayerLayer addSublayer : newAVPlayerLayer]

This causes a flicker on the screen, which is okay if the device was just an iPhone/iPad, but problem is with abrupt Airplay behaviour, causing the UISlider for sound to show in the remote controls. 这会导致屏幕闪烁,如果该设备只是iPhone / iPad,就可以了,但是Airplay行为突然出现问题,导致UISlider的声音显示在遥控器上。 Is there a way to re-initialize the AVQueuePlayer without recreating or reassigning the AVPlayerLayer? 是否可以在不重新创建或重新分配AVPlayerLayer的情况下重新初始化AVQueuePlayer?

Ended up using AVPlayer instead of AVQueuePlayer, and using method 最终使用AVPlayer而不是AVQueuePlayer并使用方法

replaceCurrentItemWithPlayerItem

Does not cause the glitch in airplay, and saves the memory as well since the items are instantiated as and when required. 不会在airplay中引起毛刺,并且由于可以在需要时实例化这些项,因此还可以节省内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM