Playing video with avplayer, listening to the loadedTimeRanges property, playing about 10 minutes of video, avplayer always preload the video, and feel very costly, is there a way to limit the size of the preloaded area? Such as pre-loading video half of the time?
I think you're looking for AVPlayerItem's preferredForwardBufferedDuration property.
Per Apple:
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.
If you use resourceLoaderdelegate
you can control the exact amount of content that gets preloaded/downloaded prior to playback.
The code example here is a good start - AVPlayer stalling on large video files using resource loader delegate
Basically, you would have to maintain an array of pendingRequests and process them once by one by firing up URLSession dataTask until you have downloaded enough content that you would like to preload.
Cheers.
© 2022 - 2024 — McMap. All rights reserved.