mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Cancel loading assets on switching backend
This commit is contained in:
parent
fe9b7c03ca
commit
815d0b3ae8
@ -62,7 +62,10 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
|
||||
var aspectRatio: Double {
|
||||
#if os(iOS)
|
||||
videoWidth! / videoHeight!
|
||||
guard let videoWidth, let videoHeight else {
|
||||
return VideoPlayerView.defaultAspectRatio
|
||||
}
|
||||
return videoWidth / videoHeight
|
||||
#else
|
||||
VideoPlayerView.defaultAspectRatio
|
||||
#endif
|
||||
@ -170,6 +173,11 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
avPlayer.replaceCurrentItem(with: nil)
|
||||
}
|
||||
|
||||
func cancelLoads() {
|
||||
asset?.cancelLoading()
|
||||
composition.cancelLoading()
|
||||
}
|
||||
|
||||
func seek(to time: CMTime, seekType _: SeekType, completionHandler: ((Bool) -> Void)?) {
|
||||
guard !model.live else { return }
|
||||
|
||||
|
@ -353,6 +353,10 @@ final class MPVBackend: PlayerBackend {
|
||||
isPlaying ? pause() : play()
|
||||
}
|
||||
|
||||
func cancelLoads() {
|
||||
stop()
|
||||
}
|
||||
|
||||
func stop() {
|
||||
client?.stop()
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ protocol PlayerBackend {
|
||||
|
||||
func setNeedsDrawing(_ needsDrawing: Bool)
|
||||
func setSize(_ width: Double, _ height: Double)
|
||||
|
||||
func cancelLoads()
|
||||
}
|
||||
|
||||
extension PlayerBackend {
|
||||
|
@ -498,6 +498,9 @@ final class PlayerModel: ObservableObject {
|
||||
let fromBackend: PlayerBackend = from == .appleAVPlayer ? avPlayerBackend : mpvBackend
|
||||
let toBackend: PlayerBackend = to == .appleAVPlayer ? avPlayerBackend : mpvBackend
|
||||
|
||||
toBackend.cancelLoads()
|
||||
fromBackend.cancelLoads()
|
||||
|
||||
if !self.backend.canPlayAtRate(currentRate) {
|
||||
currentRate = self.backend.suggestedPlaybackRates.last { $0 < currentRate } ?? 1.0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user