yattee/Model/Player/Backends/PlayerBackend.swift

104 lines
2.8 KiB
Swift
Raw Normal View History

2022-02-16 20:23:11 +00:00
import CoreMedia
import Defaults
import Foundation
protocol PlayerBackend {
var model: PlayerModel! { get set }
var controls: PlayerControlsModel! { get set }
var playerTime: PlayerTimeModel! { get set }
var networkState: NetworkStateModel! { get set }
2022-02-16 20:23:11 +00:00
var stream: Stream? { get set }
var video: Video? { get set }
var currentTime: CMTime? { get }
var loadedVideo: Bool { get }
var isLoadingVideo: Bool { get }
var isPlaying: Bool { get }
var isSeeking: Bool { get }
2022-02-16 20:23:11 +00:00
var playerItemDuration: CMTime? { get }
2022-07-09 00:21:04 +00:00
var aspectRatio: Double { get }
2022-03-27 18:59:22 +00:00
func bestPlayable(_ streams: [Stream], maxResolution: ResolutionSetting) -> Stream?
2022-02-16 20:23:11 +00:00
func canPlay(_ stream: Stream) -> Bool
func playStream(
_ stream: Stream,
of video: Video,
preservingTime: Bool,
upgrading: Bool
)
func play()
func pause()
func togglePlay()
func stop()
func seek(to time: CMTime, completionHandler: ((Bool) -> Void)?)
func seek(to seconds: Double, completionHandler: ((Bool) -> Void)?)
func seek(relative time: CMTime, completionHandler: ((Bool) -> Void)?)
func setRate(_ rate: Float)
func closeItem()
2022-08-18 22:40:46 +00:00
func closePiP()
2022-02-16 20:23:11 +00:00
2022-08-20 20:31:03 +00:00
func startMusicMode()
func stopMusicMode()
2022-02-16 20:23:11 +00:00
func updateControls()
func startControlsUpdates()
func stopControlsUpdates()
2022-08-20 20:31:03 +00:00
func didChangeTo()
2022-06-24 23:39:29 +00:00
func setNeedsNetworkStateUpdates(_ needsUpdates: Bool)
2022-02-16 20:23:11 +00:00
func setNeedsDrawing(_ needsDrawing: Bool)
2022-03-27 11:42:20 +00:00
func setSize(_ width: Double, _ height: Double)
2022-02-16 20:23:11 +00:00
}
extension PlayerBackend {
func seek(to time: CMTime, completionHandler: ((Bool) -> Void)? = nil) {
seek(to: time, completionHandler: completionHandler)
}
func seek(to seconds: Double, completionHandler: ((Bool) -> Void)? = nil) {
seek(to: .secondsInDefaultTimescale(seconds), completionHandler: completionHandler)
}
func seek(relative time: CMTime, completionHandler: ((Bool) -> Void)? = nil) {
seek(relative: time, completionHandler: completionHandler)
}
2022-07-10 22:24:56 +00:00
func eofPlaybackModeAction() {
switch model.playbackMode {
case .queue, .shuffle:
if Defaults[.closeLastItemOnPlaybackEnd] {
model.prepareCurrentItemForHistory(finished: true)
}
if model.queue.isEmpty {
if Defaults[.closeLastItemOnPlaybackEnd] {
model.resetQueue()
model.hide()
}
} else {
model.advanceToNextItem()
}
case .loopOne:
model.backend.seek(to: .zero) { _ in
self.model.play()
}
case .related:
guard let item = model.autoplayItem else { return }
model.resetAutoplay()
model.advanceToItem(item)
}
}
2022-02-16 20:23:11 +00:00
}