mirror of
https://github.com/yattee/yattee.git
synced 2025-10-10 17:38:15 +00:00
improved subtitle handling
- fix subtitle disabling not working - make subtitle adding/removing async - make subtitle menu non blocking Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
@@ -23,15 +23,14 @@ final class MPVBackend: PlayerBackend {
|
||||
|
||||
var stream: Stream?
|
||||
var video: Video?
|
||||
var captions: Captions? { didSet {
|
||||
guard let captions else {
|
||||
if client?.areSubtitlesAdded == true {
|
||||
client?.removeSubs()
|
||||
var captions: Captions? {
|
||||
didSet {
|
||||
Task {
|
||||
await handleCaptionsChange()
|
||||
}
|
||||
return
|
||||
}
|
||||
addSubTrack(captions.url)
|
||||
}}
|
||||
}
|
||||
|
||||
var currentTime: CMTime?
|
||||
|
||||
var loadedVideo = false
|
||||
@@ -617,10 +616,14 @@ final class MPVBackend: PlayerBackend {
|
||||
}
|
||||
|
||||
func addSubTrack(_ url: URL) {
|
||||
if client?.areSubtitlesAdded == true {
|
||||
client?.removeSubs()
|
||||
Task {
|
||||
if let areSubtitlesAdded = client?.areSubtitlesAdded {
|
||||
if await areSubtitlesAdded() {
|
||||
await client?.removeSubs()
|
||||
}
|
||||
}
|
||||
await client?.addSubTrack(url)
|
||||
}
|
||||
client?.addSubTrack(url)
|
||||
}
|
||||
|
||||
func setVideoToAuto() {
|
||||
@@ -684,6 +687,17 @@ final class MPVBackend: PlayerBackend {
|
||||
}
|
||||
}
|
||||
|
||||
private func handleCaptionsChange() async {
|
||||
guard let captions else {
|
||||
if let isSubtitlesAdded = client?.areSubtitlesAdded, await isSubtitlesAdded() {
|
||||
await client?.removeSubs()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
addSubTrack(captions.url)
|
||||
}
|
||||
|
||||
private func handlePropertyChange(_ name: String, _ property: mpv_event_property) {
|
||||
switch name {
|
||||
case "pause":
|
||||
|
Reference in New Issue
Block a user