AVPlayer寻求不准确

时间:2014-06-26 13:08:15

标签: ios objective-c stream streaming avplayer

所以我有一个我有AVPlayer播放的HLS流。我试图创建一个按钮,像这样跳回30秒:

- (void) rewindStream
{
    NSLog(@"Seeking...");
    NSLog(@"Current Time: %f", CMTimeGetSeconds(self.player.currentTime));
    NSLog(@"New Time: %f", CMTimeGetSeconds(CMTimeMakeWithSeconds(CMTimeGetSeconds(self.player.currentTime) - 30.0f, self.player.currentTime.timescale)));
    [self.player pause];
    CMTime cmTime = CMTimeMakeWithSeconds(CMTimeGetSeconds(self.player.currentTime) - 30.0f, self.player.currentTime.timescale);
    [self.player seekToTime:cmTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {
        NSLog(@"Complete. Current Time: %f", CMTimeGetSeconds(self.player.currentTime));
        [self.player play];
    }];
}

有时会起作用,但不会起作用。这是日志:

Seeking...
Current Time: 47.253361
New Time: 37.254001
Complete. Current Time: 37.254944
Seeking...
Current Time: 59.409800
New Time: 49.410447
Complete. Current Time: 50.103244
Seeking...
Current Time: 68.780054
New Time: 58.780436
Complete. Current Time: 60.086244
Seeking...
Current Time: 80.493733
New Time: 70.494375
Complete. Current Time: 80.140578
Seeking...
Current Time: 92.674773
New Time: 82.675062
Complete. Current Time: 110.135244

我有容差设置,我确保我有足够的时间让段下载/缓冲,以便寻求可能,但我不确定问题是什么。

非常感谢任何帮助。

感谢。

2 个答案:

答案 0 :(得分:4)

我总是使用60000的时间刻度,几乎可以提供足够的精确度。不确定这是不是你的问题,但我发现我的大多数CMTime问题都是在我解决这个问题之前发现的。 Warren Moore在http://warrenmoore.net/understanding-cmtime

上发表了一篇很好的文章

答案 1 :(得分:0)

它看起来是正确的,在我的头顶,也许是这样的?

CMTime currentTime = self.player.currentTime;
CMTime timeToSubtract = CMTimeMakeWithSeconds(30, 1);

CMTime resultTime = CMTimeSubtract(currentTime, timeToSubtract);

[self.player seekToTime:resultTime];