mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 22:30:32 +05:30
Load audio and video together with one command with MPV
This commit is contained in:
parent
a332100887
commit
3cb20452c7
@ -153,6 +153,11 @@ final class MPVBackend: PlayerBackend {
|
|||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
guard let self = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if let url = stream.singleAssetURL {
|
if let url = stream.singleAssetURL {
|
||||||
self.onFileLoaded = {
|
self.onFileLoaded = {
|
||||||
updateCurrentStream()
|
updateCurrentStream()
|
||||||
@ -164,20 +169,17 @@ final class MPVBackend: PlayerBackend {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.onFileLoaded = { [weak self] in
|
self.onFileLoaded = { [weak self] in
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
|
||||||
self?.client.addAudio(stream.audioAsset.url) { _ in
|
|
||||||
updateCurrentStream()
|
updateCurrentStream()
|
||||||
startPlaying()
|
startPlaying()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.client.loadFile(stream.videoAsset.url, time: time) { [weak self] _ in
|
self.client.loadFile(stream.videoAsset.url, audio: stream.audioAsset.url, time: time) { [weak self] _ in
|
||||||
self?.isLoadingVideo = true
|
self?.isLoadingVideo = true
|
||||||
self?.pause()
|
self?.pause()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if preservingTime {
|
if preservingTime {
|
||||||
if model.preservedTime.isNil {
|
if model.preservedTime.isNil {
|
||||||
|
@ -103,13 +103,21 @@ final class MPVClient: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFile(_ url: URL, time: CMTime? = nil, completionHandler: ((Int32) -> Void)? = nil) {
|
func loadFile(_ url: URL, audio: URL? = nil, time: CMTime? = nil, completionHandler: ((Int32) -> Void)? = nil) {
|
||||||
var args = [url.absoluteString]
|
var args = [url.absoluteString]
|
||||||
|
var options = [String]()
|
||||||
|
|
||||||
if let time = time {
|
if let time = time {
|
||||||
args.append("replace")
|
args.append("replace")
|
||||||
args.append("start=\(Int(time.seconds))")
|
options.append("start=\(Int(time.seconds))")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let audioURL = audio?.absoluteString {
|
||||||
|
options.append("audio-files-append=\"\(audioURL)\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
args.append(options.joined(separator: ","))
|
||||||
|
|
||||||
command("loadfile", args: args, returnValueCallback: completionHandler)
|
command("loadfile", args: args, returnValueCallback: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user