Start playing after video intro instead of seeking from beginning

This commit is contained in:
Arkadiusz Fal 2021-12-17 21:02:15 +01:00
parent d7058b46d3
commit 23e2e216db

View File

@ -215,7 +215,29 @@ final class PlayerModel: ObservableObject {
if self.isAutoplaying(playerItem!) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
self?.play()
guard let self = self else {
return
}
if let segment = self.sponsorBlock.segments.first,
segment.start < 3,
self.lastSkipped.isNil
{
self.player.seek(
to: segment.endTime,
toleranceBefore: .secondsInDefaultTimescale(1),
toleranceAfter: .zero
) { finished in
guard finished else {
return
}
self.lastSkipped = segment
self.play()
}
} else {
self.play()
}
}
}
}