AVPlayer seekToTime无法回头寻找

时间:2013-11-22 15:34:30

标签: objective-c cocoa avfoundation

我在播放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];
            }
        }
    }
}

持续时间为0,“就绪”仅出现在前方搜寻中。 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>>"
)

1 个答案:

答案 0 :(得分:1)

使用Bass

解决

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