Reputation: 161
I have very strange seekToTime behaviour while playing mp3 files, cannot understand how to fix.
This code
[self.avPlayer seekToTime:CMTimeMakeWithSeconds(seconds, NSEC_PER_SEC)
toleranceBefore:kCMTimeZero
toleranceAfter:kCMTimePositiveInfinity];
works ok if seconds is greater than current time, but do nothing for kCMTimeZero or if seconds is less. Status not changed after seek backward.
- (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 is 0, "ready" appeared only for forward seek. avPlayer is AVPlayer.
How to seek backward correctly? Thanks.
UPDATE
NSLog(@"Tracks from asset: %@", self.avPlayer.currentItem.asset.tracks);
NSLog(@"Tracks from file: %@", self.avPlayer.currentItem.tracks);
Result:
Tracks from asset: ()
Tracks from file: (
"<AVPlayerItemTrack: 0x608000019850, assetTrack = <AVAssetTrack: 0x60000000d2e0, trackID = 1, mediaType = soun>>",
"<AVPlayerItemTrack: 0x608000019810, assetTrack = <AVAssetTrack: 0x60000000d320, trackID = 2, mediaType = meta>>"
)
Upvotes: 3
Views: 1090
Reputation: 161
Solved using Bass
Also, AudioStreamer has a lot of bugs, but solve this issue too.
Upvotes: 1