AVPlayer stops playing video after buffering

后端 未结 1 849
-上瘾入骨i
-上瘾入骨i 2020-12-05 08:48

When I load a video from the internet (10-40MB large) I am unable to provide a smooth playing experience.

My AVPlayer either loads the whole video and then plays it,

相关标签:
1条回答
  • 2020-12-05 09:22

    Since iOS 10.x, you can make some buffer settings, for example you can decide how many seconds you'll need to buffering your video:

        if #available(iOS 10.0, tvOS 10.0, OSX 10.12, *) {
            avPlayer?.automaticallyWaitsToMinimizeStalling = .playWhenBufferNotEmpty
            //preferredForwardBufferDuration -> default is 0, which means `AVPlayer` handle it independently, try more seconds like 5 or 10.
            playerItem.preferredForwardBufferDuration = TimeInterval(5) 
        }
    
    0 讨论(0)
提交回复
热议问题