SRGSSR / srgmediaplayer-apple

An advanced media player library, simple and reliable
MIT License
158 stars 33 forks source link

Seek to position sometimes does not fulfill tolerance settings #55

Closed defagos closed 2 years ago

defagos commented 5 years ago

For some tolerance settings and start position, and depending on where the time to seek to is located within a chunk, tolerance settings are not correctly applied, and playback might start outside the tolerated range.

This issue is an AVPlayer issue or limitation, or there is something I did not correctly understand with -seekToTime:toleranceBefore:toleranceAfter:completionHandler::

AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
NSURL *URL = [NSURL URLWithString:@"http://stream-i.akamaihd.net/i/tj/2016/tj_20160905_full_f_965656-,101,301,701,1201,k.mp4.csmil/master.m3u8"];
AVPlayer *player = [AVPlayer playerWithURL:URL];
playerViewController.player = player;
[self presentViewController:playerViewController animated:YES completion:^{
    [player seekToTime:CMTimeMakeWithSeconds(219., NSEC_PER_SEC) toleranceBefore:CMTimeMakeWithSeconds(3., NSEC_PER_SEC) toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {
        [player play];
    }];
}];

Playback would in this case be expected to start in [216, inf], but will actually start at the beginning of the chunk near 212.

defagos commented 5 years ago

Seek is sharp for

[self presentViewController:playerViewController animated:YES completion:^{
    [player seekToTime:CMTimeMakeWithSeconds(219., NSEC_PER_SEC) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {
        [player play];
    }];
}];

but jumps to 212, even for small tolerances:

[self presentViewController:playerViewController animated:YES completion:^{
    [player seekToTime:CMTimeMakeWithSeconds(219., NSEC_PER_SEC) toleranceBefore:CMTimeMakeWithSeconds(0.1, NSEC_PER_SEC) toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {
        [player play];
    }];
}];

What is puzzling me is that playback also starts at 212 if we set a small tolerance after:

[self presentViewController:playerViewController animated:YES completion:^{
    [player seekToTime:CMTimeMakeWithSeconds(219., NSEC_PER_SEC) toleranceBefore:kCMTimeZero toleranceAfter:CMTimeMakeWithSeconds(0.1, NSEC_PER_SEC) completionHandler:^(BOOL finished) {
        [player play];
    }];
}];
defagos commented 5 years ago

I opened a radar for this issue.

defagos commented 5 years ago

I fixed related unit tests (and ensured they break with the current behavior, highlighting the issue). This is available on the feature/imprecise-seeks branch.

defagos commented 5 years ago

Still waiting for an answer from Apple.

defagos commented 5 years ago

Not fixed in iOS 12.1.

defagos commented 4 years ago

Still not fixed in iOS 13.5.

defagos commented 2 years ago

Fixed as of iOS 14. I closed my radar accordingly.