mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Improve MPV loading commands
This commit is contained in:
parent
c0c9967bfd
commit
208ba623e5
@ -168,12 +168,15 @@ final class MPVBackend: PlayerBackend {
|
||||
self?.isLoadingVideo = true
|
||||
}
|
||||
} else {
|
||||
self.onFileLoaded = { [weak self] in
|
||||
self.onFileLoaded = {
|
||||
updateCurrentStream()
|
||||
startPlaying()
|
||||
}
|
||||
|
||||
self.client.loadFile(stream.videoAsset.url, audio: stream.audioAsset.url, time: time) { [weak self] _ in
|
||||
let fileToLoad = self.model.musicMode ? stream.audioAsset.url : stream.videoAsset.url
|
||||
let audioTrack = self.model.musicMode ? nil : stream.audioAsset.url
|
||||
|
||||
self.client.loadFile(fileToLoad, audio: audioTrack, time: time) { [weak self] _ in
|
||||
self?.isLoadingVideo = true
|
||||
self?.pause()
|
||||
}
|
||||
@ -386,4 +389,16 @@ final class MPVBackend: PlayerBackend {
|
||||
func setSize(_ width: Double, _ height: Double) {
|
||||
self.client?.setSize(width, height)
|
||||
}
|
||||
|
||||
func addVideoTrack(_ url: URL) {
|
||||
self.client?.addVideoTrack(url)
|
||||
}
|
||||
|
||||
func setVideoToAuto() {
|
||||
self.client?.setVideoToAuto()
|
||||
}
|
||||
|
||||
func setVideoToNo() {
|
||||
self.client?.setVideoToNo()
|
||||
}
|
||||
}
|
||||
|
@ -121,10 +121,6 @@ final class MPVClient: ObservableObject {
|
||||
command("loadfile", args: args, returnValueCallback: completionHandler)
|
||||
}
|
||||
|
||||
func addAudio(_ url: URL, completionHandler: ((Int32) -> Void)? = nil) {
|
||||
command("audio-add", args: [url.absoluteString], returnValueCallback: completionHandler)
|
||||
}
|
||||
|
||||
func play() {
|
||||
setFlagAsync("pause", false)
|
||||
}
|
||||
@ -228,6 +224,22 @@ final class MPVClient: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
func addVideoTrack(_ url: URL) {
|
||||
command("video-add", args: [url.absoluteString])
|
||||
}
|
||||
|
||||
func setVideoToAuto() {
|
||||
setString("video", "auto")
|
||||
}
|
||||
|
||||
func setVideoToNo() {
|
||||
setString("video", "no")
|
||||
}
|
||||
|
||||
var tracksCount: Int {
|
||||
Int(getString("track-list/count") ?? "-1") ?? -1
|
||||
}
|
||||
|
||||
private func setFlagAsync(_ name: String, _ flag: Bool) {
|
||||
var data: Int = flag ? 1 : 0
|
||||
mpv_set_property_async(mpv, 0, name, MPV_FORMAT_FLAG, &data)
|
||||
@ -244,6 +256,23 @@ final class MPVClient: ObservableObject {
|
||||
return data
|
||||
}
|
||||
|
||||
private func getInt(_ name: String) -> Int {
|
||||
var data = Int64()
|
||||
mpv_get_property(mpv, name, MPV_FORMAT_INT64, &data)
|
||||
return Int(data)
|
||||
}
|
||||
|
||||
func getString(_ name: String) -> String? {
|
||||
let cstr = mpv_get_property_string(mpv, name)
|
||||
let str: String? = cstr == nil ? nil : String(cString: cstr!)
|
||||
mpv_free(cstr)
|
||||
return str
|
||||
}
|
||||
|
||||
private func setString(_ name: String, _ value: String) {
|
||||
mpv_set_property_string(mpv, name, value)
|
||||
}
|
||||
|
||||
private func makeCArgs(_ command: String, _ args: [String?]) -> [String?] {
|
||||
if !args.isEmpty, args.last == nil {
|
||||
fatalError("Command do not need a nil suffix")
|
||||
|
Loading…
Reference in New Issue
Block a user