While testing my app on iOS 14, I found some mp3-format files not working properly. There's no error from start to end, but sounds only heard in the very beginning and muted in the following seconds.
Here are sample codes to reproduce.
I have looked into it for some time and found:
Here are sample codes to reproduce.
Code Block objective-c NSURL *url = [NSURL URLWithString:urlString]; BOOL preferPreciseDuration = YES; NSDictionary *options = @{AVURLAssetPreferPreciseDurationAndTimingKey: @(preferPreciseDuration)}; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:options]; AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset]; [playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew context:nil]; player = [AVPlayer playerWithPlayerItem:playerItem]; [player play];
I have looked into it for some time and found:
This problem only occurs on iOS 14+.
If I omit AVURLAssetPreferPreciseDurationAndTimingKey option, everything works fine.
It seems to be server-related, I have tested two URLs hosting exact same file, but one works while the other doesn't.
On the same server, file1 works while file2 doesn't.