gpt4 book ai didi

objective-c - AVPlayer seekToTime 不适用于寻回

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:09 25 4
gpt4 key购买 nike

我在播放 mp3 文件时有非常奇怪的 seekToTime 行为,不知道如何解决。

这段代码

    [self.avPlayer seekToTime:CMTimeMakeWithSeconds(seconds, NSEC_PER_SEC) 
toleranceBefore:kCMTimeZero
toleranceAfter:kCMTimePositiveInfinity];

如果秒数大于当前时间,则工作正常,但不对 kCMTimeZero 或秒数小于当前时间执行任何操作。向后查找后状态没有改变。

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self.avPlayer.currentItem) {
if ([keyPath isEqualToString:@"status"]) {
if (self.avPlayer.status == AVPlayerStatusReadyToPlay && self.player.play) {
NSLog(@"Ready");
NSLog(@"%lli", self.avPlayer.currentItem.duration.value);
[self.avPlayer play];
}
}
}
}

Duration为0,“ready”只在forward seek时出现。 avPlayer 是 AVPlayer。

如何正确的向后查找?谢谢。

更新

NSLog(@"Tracks from asset: %@", self.avPlayer.currentItem.asset.tracks);
NSLog(@"Tracks from file: %@", self.avPlayer.currentItem.tracks);

结果:

Tracks from asset: ()
Tracks from file: (
"<AVPlayerItemTrack: 0x608000019850, assetTrack = <AVAssetTrack: 0x60000000d2e0, trackID = 1, mediaType = soun>>",
"<AVPlayerItemTrack: 0x608000019810, assetTrack = <AVAssetTrack: 0x60000000d320, trackID = 2, mediaType = meta>>"
)

最佳答案

使用 Bass 解决

此外,AudioStreamer有很多错误,但也解决了这个问题。

关于objective-c - AVPlayer seekToTime 不适用于寻回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20148620/

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