Watch Next behavior and settings

This commit is contained in:
Arkadiusz Fal
2022-12-18 19:39:03 +01:00
parent b90c856e21
commit 39fc23c5dc
23 changed files with 487 additions and 451 deletions

View File

@@ -531,10 +531,6 @@ final class AVPlayerBackend: PlayerBackend {
}
@objc func itemDidPlayToEndTime() {
if Defaults[.closeLastItemOnPlaybackEnd] {
model.prepareCurrentItemForHistory(finished: true)
}
eofPlaybackModeAction()
}

View File

@@ -94,37 +94,59 @@ extension PlayerBackend {
}
func eofPlaybackModeAction() {
let timer = Delay.by(5) {
let loopAction = {
model.backend.seek(to: .zero, seekType: .loopRestart) { _ in
self.model.play()
}
}
guard model.playbackMode != .loopOne else {
loopAction()
return
}
let action = {
switch model.playbackMode {
case .queue, .shuffle:
if Defaults[.closeLastItemOnPlaybackEnd] {
model.prepareCurrentItemForHistory(finished: true)
}
model.prepareCurrentItemForHistory(finished: true)
if model.queue.isEmpty {
if Defaults[.closeLastItemOnPlaybackEnd] {
#if os(tvOS)
if model.activeBackend == .appleAVPlayer {
model.avPlayerBackend.controller?.dismiss(animated: false)
}
#endif
model.resetQueue()
model.hide()
}
#if os(tvOS)
if model.activeBackend == .appleAVPlayer {
model.avPlayerBackend.controller?.dismiss(animated: false)
}
#endif
model.resetQueue()
model.hide()
} else {
model.advanceToNextItem()
}
case .loopOne:
model.backend.seek(to: .zero, seekType: .loopRestart) { _ in
self.model.play()
}
loopAction()
case .related:
guard let item = model.autoplayItem else { return }
model.resetAutoplay()
model.advanceToItem(item)
}
}
WatchNextViewModel.shared.prepareForNextItem(model.currentItem, timer: timer)
let actionAndHideWatchNext: (Bool) -> Void = { delay in
WatchNextViewModel.shared.hide()
if delay {
Delay.by(0.3) {
action()
}
} else {
action()
}
}
if Defaults[.openWatchNextOnFinishedWatching], model.presentingPlayer {
let timer = Delay.by(TimeInterval(Defaults[.openWatchNextOnFinishedWatchingDelay]) ?? 5.0) {
actionAndHideWatchNext(true)
}
WatchNextViewModel.shared.finishedWatching(model.currentItem, timer: timer)
} else {
actionAndHideWatchNext(false)
}
}
func updateControls(completionHandler: (() -> Void)? = nil) {