简体   繁体   中英

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

(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. 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 :

[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. Is there a way to re-initialize the AVQueuePlayer without recreating or reassigning the AVPlayerLayer?

Ended up using AVPlayer instead of AVQueuePlayer, and using method

replaceCurrentItemWithPlayerItem

Does not cause the glitch in airplay, and saves the memory as well since the items are instantiated as and when required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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