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