iOS AVPlayer cancel buffering

笑着哭i 提交于 2019-12-12 10:58:08

问题


If I load an AVPlayer with a file from a host with

[AVPlayer playerWithPlayerItem:playerItem];

And the "buffering" takes longer than the user wants, how do I allow them to cancel it?


回答1:


So the correct answer is @Che with:

If you will call [self.player replaceCurrentItemWithPlayerItem:nil]; buffering stops. – Che Oct 13 at 14:36

and you do so on the observer listening for the status update from the playerWithPlayerItem. Thanks All!




回答2:


I don't think there is a method to directly stop buffering. But you can check the boolean playbackLikelyToKeepUp property of the AVPlayerItem to check if the buffer is loading. I not then pause playback on the AVPlayer.




回答3:


Swift 3

player?.replaceCurrentItem(with: nil)



回答4:


you can try this

// pause buffer
[self.playerItem cancelPendingSeeks];
[self.playerItem.asset cancelLoading];



回答5:


You need to manage preferredForwardBufferDuration of avplayer currentItem. If you want to stop buffering set value to 1 because if you set it to 0 it will be set up automatically

self.avPlayer.currentItem.preferredForwardBufferDuration = 1;

From Apple documentation: This property defines the preferred forward buffer duration in seconds. If set to 0, the player will choose an appropriate level of buffering for most use cases. Setting this property to a low value will increase the chance that playback will stall and re-buffer, while setting it to a high value will increase demand on system resources.



来源:https://stackoverflow.com/questions/32892520/ios-avplayer-cancel-buffering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!