Improve EOF handling

This commit is contained in:
Arkadiusz Fal 2022-04-03 16:46:33 +02:00
parent 512899235e
commit 57d00053d8

View File

@ -17,7 +17,17 @@ final class MPVBackend: PlayerBackend {
var loadedVideo = false var loadedVideo = false
var isLoadingVideo = true { didSet { var isLoadingVideo = true { didSet {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
self?.controls.isLoadingVideo = self?.isLoadingVideo ?? true guard let self = self else {
return
}
self.controls.isLoadingVideo = self.isLoadingVideo
if !self.isLoadingVideo {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [weak self] in
self?.handleEOF = true
}
}
} }
}} }}
@ -39,6 +49,7 @@ final class MPVBackend: PlayerBackend {
private var clientTimer: RepeatingTimer! private var clientTimer: RepeatingTimer!
private var handleEOF = false
private var onFileLoaded: (() -> Void)? private var onFileLoaded: (() -> Void)?
private var controlsUpdates = false private var controlsUpdates = false
@ -65,6 +76,7 @@ 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
let updateCurrentStream = { let updateCurrentStream = {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
self?.stream = stream self?.stream = stream
@ -299,7 +311,7 @@ final class MPVBackend: PlayerBackend {
} }
func handleEndOfFile(_: UnsafePointer<mpv_event>!) { func handleEndOfFile(_: UnsafePointer<mpv_event>!) {
guard !isLoadingVideo else { guard handleEOF, !isLoadingVideo else {
return return
} }