Alex Rivera | Logout

AVPlayer seekToTime does not play at correct position

Asked 2012-07-13T01:14:37.320
38

I have an AVPlayer which is playing a HLS video stream. My user interface provides a row of buttons, one for each "chapter" in the video (the buttons are labeled "1", "2", "3"). The app downloads some meta-data from a server which contains the list of chapter cut-in points denoted in seconds. For example, one video is 12 minutes in length - the list of chapter cut-in points are 0, 58, 71, 230, 530, etc., etc.

When the user taps one of the "chapter buttons" the button handler code does this:

            [self.avPlayer pause];

    [self.avPlayer seekToTime: CMTimeMakeWithSeconds(seekTime, 600) 
              toleranceBefore: kCMTimeZero 
               toleranceAfter: kCMTimeZero 
            completionHandler: ^(BOOL finished) 
            {
                [self.avPlayer play];
            }];

Where "seekTime" is a local var which contains the cut-in point (as described above).

The problem is that the video does not always start at the correct point. Sometimes it does. But sometimes it is anywhere from a tenth of a second, to 2 seconds BEFORE the requested seekTime. It NEVER starts after the requested seekTime.

Here are some stats on the video encoding:

Encoder: handbrakeCLI Codec: h.264 Frame rate: 24 (actually, 23.976 - same as how it was shot) Video Bitrate: multiple bitrates (64/150/300/500/800/1200) Audio Bitrate: 128k Keyframes: 23.976 (1 per second)

I am using the Apple mediafilesegmenter tool, of course, and the variantplaylistcreator to generate the playlist.

The files are being served from an Amazon Cloud/S3 bucket.

One area which I remain unclear about is CMTimeMakeWithSeconds - I have tried several variations based on different articles/docs I have read. For example, in the above excerpt I am using:

CMTimeMakeWithSeconds(seekTime, 600)

I have also tried:

CMTimeMakeWithSeconds(seekTime, 1)

I can't tell which is correct, tho

Edit
Report

1 Answer

1

please use function like [player seekToTime:CMTimeMakeWithSeconds(seekTime,1)] .
Because your tolerance value kCMTimeZero will take more time to seek.Instead of using tolerance value of kCMTimeZero you can use kCMTimeIndefinite which is equivalent the function that i specified earlier.

answered 2013-01-30T16:52:24.690

Your Answer