gpt4 book ai didi

ios - AVPlayer seekToTime : backward not working

转载 作者:可可西里 更新时间:2023-11-01 03:30:02 30 4
gpt4 key购买 nike

我有以下代码:

AVPlayerItem *currentItem = [AVPlayerItem playerItemWithURL:soundURL];
[self.audioPlayer replaceCurrentItemWithPlayerItem:currentItem];
[self.audioPlayer play];

其中 soundURL 是一个 remoteURL。它工作正常。 AVPlayer 完美播放音乐。我有一个进度条,我正在根据玩家的当前时间更新它。

一切正常。我的问题是,当我向前拖动进度条时,audioplayer 从新位置开始,但如果我拖动 progressbar 它不会从新位置开始,实际上它会恢复从以前的位置。这是我的进度条拖动开始和停止代码:

- (IBAction)progressBarDraggingStart:(id)sender
{
if (self.audioPlayer.rate != 0.0)
{
[self.audioPlayer pause];
}
}

- (IBAction)progressBarDraggindStop:(id)sender
{
CMTime newTime = CMTimeMakeWithSeconds(self.progressBar.value, 1);
[self.audioPlayer seekToTime:newTime];
[self.audioPlayer play];
}

谁能帮我解决这个问题?

最佳答案

我建议做几件事。首先,获取 timescale 值并将其传递给 CMTime 结构。其次,使用 seekToTime:toleranceBefore:toleranceAfter:completionHandler: 方法进行更准确的查找。例如,您的代码如下所示:

- (IBAction)progressBarDraggindStop:(id)sender {
int32_t timeScale = self.audioPlayer.currentItem.asset.duration.timescale;

[self.audioPlayer seekToTime: CMTimeMakeWithSeconds(self.progressBar.value, timeScale)
toleranceBefore: kCMTimeZero
toleranceAfter: kCMTimeZero
completionHandler: ^(BOOL finished) {
[self.audioPlayer play];
}];
}

关于ios - AVPlayer seekToTime : backward not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21992538/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com