mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
Fix handling EOF with MPV (#201)
This commit is contained in:
parent
9cb6ff64ff
commit
11ef8c4dfc
@ -30,13 +30,6 @@ final class MPVBackend: PlayerBackend {
|
|||||||
|
|
||||||
self.controls?.isLoadingVideo = self.isLoadingVideo
|
self.controls?.isLoadingVideo = self.isLoadingVideo
|
||||||
self.setNeedsNetworkStateUpdates(true)
|
self.setNeedsNetworkStateUpdates(true)
|
||||||
|
|
||||||
if !self.isLoadingVideo {
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [weak self] in
|
|
||||||
self?.handleEOF = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.model?.objectWillChange.send()
|
self.model?.objectWillChange.send()
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -77,7 +70,6 @@ final class MPVBackend: PlayerBackend {
|
|||||||
private var clientTimer: Repeater!
|
private var clientTimer: Repeater!
|
||||||
private var networkStateTimer: Repeater!
|
private var networkStateTimer: Repeater!
|
||||||
|
|
||||||
private var handleEOF = false
|
|
||||||
private var onFileLoaded: (() -> Void)?
|
private var onFileLoaded: (() -> Void)?
|
||||||
|
|
||||||
private var controlsUpdates = false
|
private var controlsUpdates = false
|
||||||
@ -157,7 +149,6 @@ final class MPVBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func playStream(_ stream: Stream, of video: Video, preservingTime: Bool, upgrading _: Bool) {
|
func playStream(_ stream: Stream, of video: Video, preservingTime: Bool, upgrading _: Bool) {
|
||||||
handleEOF = false
|
|
||||||
#if !os(macOS)
|
#if !os(macOS)
|
||||||
if model.presentingPlayer {
|
if model.presentingPlayer {
|
||||||
UIApplication.shared.isIdleTimerDisabled = true
|
UIApplication.shared.isIdleTimerDisabled = true
|
||||||
@ -304,7 +295,6 @@ final class MPVBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func closeItem() {
|
func closeItem() {
|
||||||
handleEOF = false
|
|
||||||
client?.pause()
|
client?.pause()
|
||||||
client?.stop()
|
client?.stop()
|
||||||
}
|
}
|
||||||
@ -406,6 +396,7 @@ final class MPVBackend: PlayerBackend {
|
|||||||
onFileLoaded = nil
|
onFileLoaded = nil
|
||||||
|
|
||||||
case MPV_EVENT_PAUSE:
|
case MPV_EVENT_PAUSE:
|
||||||
|
DispatchQueue.main.async { [weak self] in self?.handleEndOfFile() }
|
||||||
isPlaying = false
|
isPlaying = false
|
||||||
networkStateTimer.start()
|
networkStateTimer.start()
|
||||||
|
|
||||||
@ -419,9 +410,7 @@ final class MPVBackend: PlayerBackend {
|
|||||||
isSeeking = true
|
isSeeking = true
|
||||||
|
|
||||||
case MPV_EVENT_END_FILE:
|
case MPV_EVENT_END_FILE:
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in self?.handleEndOfFile() }
|
||||||
self?.handleEndOfFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logger.info(.init(stringLiteral: "UNHANDLED event: \(String(cString: mpv_event_name(event.pointee.event_id)))"))
|
logger.info(.init(stringLiteral: "UNHANDLED event: \(String(cString: mpv_event_name(event.pointee.event_id)))"))
|
||||||
@ -429,7 +418,7 @@ final class MPVBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleEndOfFile() {
|
func handleEndOfFile() {
|
||||||
guard handleEOF, !isLoadingVideo else {
|
guard client.eofReached else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +176,10 @@ final class MPVClient: ObservableObject {
|
|||||||
mpv.isNil ? false : getFlag("paused-for-cache")
|
mpv.isNil ? false : getFlag("paused-for-cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var eofReached: Bool {
|
||||||
|
mpv.isNil ? false : getFlag("eof-reached")
|
||||||
|
}
|
||||||
|
|
||||||
func seek(relative time: CMTime, completionHandler: ((Bool) -> Void)? = nil) {
|
func seek(relative time: CMTime, completionHandler: ((Bool) -> Void)? = nil) {
|
||||||
guard !seeking else {
|
guard !seeking else {
|
||||||
logger.warning("ignoring seek, another in progress")
|
logger.warning("ignoring seek, another in progress")
|
||||||
|
Loading…
Reference in New Issue
Block a user