我在播放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>>"
)