mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Watch next view
This commit is contained in:
@@ -107,6 +107,8 @@ struct OpenVideosModel {
|
||||
prepending: playbackMode == .playNow || playbackMode == .playNext
|
||||
)
|
||||
|
||||
WatchNextViewModel.shared.presentingOutro = false
|
||||
|
||||
if playbackMode == .playNow || playbackMode == .shuffleAll {
|
||||
#if os(iOS)
|
||||
if player.presentingPlayer {
|
||||
|
@@ -94,34 +94,37 @@ extension PlayerBackend {
|
||||
}
|
||||
|
||||
func eofPlaybackModeAction() {
|
||||
switch model.playbackMode {
|
||||
case .queue, .shuffle:
|
||||
if Defaults[.closeLastItemOnPlaybackEnd] {
|
||||
model.prepareCurrentItemForHistory(finished: true)
|
||||
}
|
||||
|
||||
if model.queue.isEmpty {
|
||||
let timer = Delay.by(5) {
|
||||
switch model.playbackMode {
|
||||
case .queue, .shuffle:
|
||||
if Defaults[.closeLastItemOnPlaybackEnd] {
|
||||
#if os(tvOS)
|
||||
if model.activeBackend == .appleAVPlayer {
|
||||
model.avPlayerBackend.controller?.dismiss(animated: false)
|
||||
}
|
||||
#endif
|
||||
model.resetQueue()
|
||||
model.hide()
|
||||
model.prepareCurrentItemForHistory(finished: true)
|
||||
}
|
||||
} else {
|
||||
model.advanceToNextItem()
|
||||
|
||||
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()
|
||||
}
|
||||
} else {
|
||||
model.advanceToNextItem()
|
||||
}
|
||||
case .loopOne:
|
||||
model.backend.seek(to: .zero, seekType: .loopRestart) { _ in
|
||||
self.model.play()
|
||||
}
|
||||
case .related:
|
||||
guard let item = model.autoplayItem else { return }
|
||||
model.resetAutoplay()
|
||||
model.advanceToItem(item)
|
||||
}
|
||||
case .loopOne:
|
||||
model.backend.seek(to: .zero, seekType: .loopRestart) { _ in
|
||||
self.model.play()
|
||||
}
|
||||
case .related:
|
||||
guard let item = model.autoplayItem else { return }
|
||||
model.resetAutoplay()
|
||||
model.advanceToItem(item)
|
||||
}
|
||||
WatchNextViewModel.shared.prepareForNextItem(model.currentItem, timer: timer)
|
||||
}
|
||||
|
||||
func updateControls(completionHandler: (() -> Void)? = nil) {
|
||||
|
@@ -322,6 +322,8 @@ final class PlayerModel: ObservableObject {
|
||||
func play(_ video: Video, at time: CMTime? = nil, showingPlayer: Bool = true) {
|
||||
pause()
|
||||
|
||||
WatchNextViewModel.shared.presentingOutro = false
|
||||
|
||||
var changeBackendHandler: (() -> Void)?
|
||||
|
||||
if let backend = (live && forceAVPlayerForLiveStreams) ? PlayerBackendType.appleAVPlayer :
|
||||
@@ -569,7 +571,7 @@ final class PlayerModel: ObservableObject {
|
||||
}
|
||||
|
||||
func closeCurrentItem(finished: Bool = false) {
|
||||
controls.hide()
|
||||
controls.presentingControls = false
|
||||
pause()
|
||||
closePiP()
|
||||
|
||||
|
@@ -10,6 +10,7 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
func play(_ videos: [Video], shuffling: Bool = false) {
|
||||
WatchNextViewModel.shared.presentingOutro = false
|
||||
playbackMode = shuffling ? .shuffle : .queue
|
||||
|
||||
videos.forEach { enqueueVideo($0, loadDetails: false) }
|
||||
@@ -48,7 +49,10 @@ extension PlayerModel {
|
||||
|
||||
comments.reset()
|
||||
stream = nil
|
||||
WatchNextViewModel.shared.close()
|
||||
|
||||
withAnimation {
|
||||
aspectRatio = VideoPlayerView.defaultAspectRatio
|
||||
currentItem = item
|
||||
}
|
||||
|
||||
@@ -163,6 +167,7 @@ extension PlayerModel {
|
||||
|
||||
remove(newItem)
|
||||
|
||||
WatchNextViewModel.shared.close()
|
||||
currentItem = newItem
|
||||
currentItem.playbackTime = time
|
||||
|
||||
@@ -207,6 +212,8 @@ extension PlayerModel {
|
||||
|
||||
if play {
|
||||
withAnimation {
|
||||
aspectRatio = VideoPlayerView.defaultAspectRatio
|
||||
WatchNextViewModel.shared.close()
|
||||
currentItem = item
|
||||
}
|
||||
videoBeingOpened = video
|
||||
|
47
Model/WatchNextViewModel.swift
Normal file
47
Model/WatchNextViewModel.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class WatchNextViewModel: ObservableObject {
|
||||
static let animation = Animation.easeIn(duration: 0.25)
|
||||
static let shared = WatchNextViewModel()
|
||||
|
||||
@Published var item: PlayerQueueItem?
|
||||
@Published var presentingOutro = true
|
||||
@Published var isAutoplaying = true
|
||||
var timer: Timer?
|
||||
|
||||
func prepareForEmptyPlayerPlaceholder(_ item: PlayerQueueItem? = nil) {
|
||||
self.item = item
|
||||
}
|
||||
|
||||
func prepareForNextItem(_ item: PlayerQueueItem? = nil, timer: Timer? = nil) {
|
||||
self.item = item
|
||||
self.timer?.invalidate()
|
||||
self.timer = timer
|
||||
isAutoplaying = true
|
||||
withAnimation(Self.animation) {
|
||||
presentingOutro = true
|
||||
}
|
||||
}
|
||||
|
||||
func cancelAutoplay() {
|
||||
timer?.invalidate()
|
||||
isAutoplaying = false
|
||||
}
|
||||
|
||||
func open() {
|
||||
withAnimation(Self.animation) {
|
||||
presentingOutro = true
|
||||
}
|
||||
}
|
||||
|
||||
func close() {
|
||||
withAnimation(Self.animation) {
|
||||
presentingOutro = false
|
||||
}
|
||||
}
|
||||
|
||||
func resetItem() {
|
||||
item = nil
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user