mpvkit implementation fixes

This commit is contained in:
Arkadiusz Fal
2023-09-23 16:42:46 +02:00
parent 4cd03f35f7
commit 13d5bd39af
8 changed files with 49 additions and 17 deletions

View File

@@ -4,9 +4,9 @@ import Defaults
import Foundation
import Logging
import MediaPlayer
import MPVKit
import Repeat
import SwiftUI
import MPVKit
final class MPVBackend: PlayerBackend {
static var timeUpdateInterval = 0.5
@@ -464,6 +464,13 @@ final class MPVBackend: PlayerBackend {
startClientUpdates()
onFileLoaded = nil
case MPV_EVENT_PROPERTY_CHANGE:
let dataOpaquePtr = OpaquePointer(event.pointee.data)
if let property = UnsafePointer<mpv_event_property>(dataOpaquePtr)?.pointee {
let propertyName = String(cString: property.name)
handlePropertyChange(propertyName, property)
}
case MPV_EVENT_PLAYBACK_RESTART:
isLoadingVideo = false
isSeeking = false
@@ -584,4 +591,22 @@ final class MPVBackend: PlayerBackend {
stopMusicMode()
}
}
private func handlePropertyChange(_ name: String, _ property: mpv_event_property) {
switch name {
case "pause":
if let paused = UnsafePointer<Bool>(OpaquePointer(property.data))?.pointee {
if paused {
DispatchQueue.main.async { [weak self] in self?.handleEndOfFile() }
} else {
isLoadingVideo = false
isSeeking = false
}
isPlaying = !paused
networkStateTimer.start()
}
default:
logger.info("MPV backend received unhandled property: \(name)")
}
}
}