I am using AVPlayer to play videos. The lenght of them is short, 2-5 second. They are played in a random order. The problem is, when changing video, and a new video starts to play, the device lags for a very short time, but i wan't the change to be fluid. Is there a way to preload videos with AVPlayer?
Asked
Active
Viewed 9,395 times
1 Answers
4
Try using AVQueuePlayer
. I am assuming that what you described as a lag, in fact is the pre buffering delay. This should be minimized or actually entirely be gotten rid of when using AVQueuePlayer
as that baby will buffer the next AVPlayerItem
while playing the current one.
From the AVFoundation documentation:
On iOS 4.1 and later, you can use an AVQueuePlayer object to play a number of items in sequence (AVQueuePlayer is a subclass of AVPlayer).
Also see Mihai's answer on Pre-buffering-for-avqueueplayer.
-
9Apple Developer Support just confirmed to me that AVQueuePlayer does not buffer video items. – midas06 Apr 10 '13 at 19:41
-
@midas06 is right. No buffering. You still get a gap between videos. – Jordan Smith Nov 16 '14 at 22:39
-
@midas06 @Jordan, make sure you're giving `insertItem` enough time to queue items for a gapless transition. If they are short enough items, you may have to queue multiple items before the very first item is played. You may find key value observers helpful to determine when a player item is ready. Also setting tolerances may help `playerItem.seekToTime(startTime, toleranceBefore: kCMTimeZero, toleranceAfter:kCMTimeZero)` – mgamba Jun 24 '16 at 23:34
-
Follow this answer. http://stackoverflow.com/questions/4218090/pre-buffering-for-avqueueplayer/39036307#39036307 Might be helpful for you. – iPatel Aug 19 '16 at 10:12
-
1