allow user to choose captions color

This commit is contained in:
Toni Förster 2024-05-20 17:17:52 +02:00
parent 96df7fdec5
commit 108b4de483
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
3 changed files with 36 additions and 8 deletions

View File

@ -68,7 +68,8 @@ final class MPVClient: ObservableObject {
checkError(mpv_set_option_string(mpv, "vo", "libmpv")) checkError(mpv_set_option_string(mpv, "vo", "libmpv"))
checkError(mpv_set_option_string(mpv, "demuxer-lavf-analyzeduration", "1")) checkError(mpv_set_option_string(mpv, "demuxer-lavf-analyzeduration", "1"))
checkError(mpv_set_option_string(mpv, "deinterlace", Defaults[.mpvDeinterlace] ? "yes" : "no")) checkError(mpv_set_option_string(mpv, "deinterlace", Defaults[.mpvDeinterlace] ? "yes" : "no"))
checkError(mpv_set_option_string(mpv, "sub-scale", "\(Defaults[.captionsFontScaleSize])")) checkError(mpv_set_option_string(mpv, "sub-scale", Defaults[.captionsFontScaleSize]))
checkError(mpv_set_option_string(mpv, "sub-color", Defaults[.captionsFontColor]))
checkError(mpv_initialize(mpv)) checkError(mpv_initialize(mpv))
@ -414,8 +415,12 @@ final class MPVClient: ObservableObject {
setString("sub", "no") setString("sub", "no")
} }
func setSubFontSize() { func setSubFontSize(scaleSize: String) {
setString("sub-scale", "\(Defaults[.captionsFontScaleSize])") setString("sub-scale", scaleSize)
}
func setSubFontColor(color: String) {
setString("sub-color", color)
} }
var tracksCount: Int { var tracksCount: Int {

View File

@ -305,7 +305,8 @@ extension Defaults.Keys {
static let captionsLanguageCode = Key<String?>("captionsLanguageCode") static let captionsLanguageCode = Key<String?>("captionsLanguageCode")
static let captionsDefaultLanguageCode = Key<String>("captionsDefaultLanguageCode", default: LanguageCodes.English.rawValue) static let captionsDefaultLanguageCode = Key<String>("captionsDefaultLanguageCode", default: LanguageCodes.English.rawValue)
static let captionsFallbackLanguageCode = Key<String>("captionsDefaultFallbackCode", default: LanguageCodes.English.rawValue) static let captionsFallbackLanguageCode = Key<String>("captionsDefaultFallbackCode", default: LanguageCodes.English.rawValue)
static let captionsFontScaleSize = Key<Float>("captionsFontScale", default: 1.0) static let captionsFontScaleSize = Key<String>("captionsFontScale", default: "1.0")
static let captionsFontColor = Key<String>("captionsFontColor", default: "#FFFFFF")
static let lastUsedPlaylistID = Key<Playlist.ID?>("lastPlaylistID") static let lastUsedPlaylistID = Key<Playlist.ID?>("lastPlaylistID")
static let lastAccountIsPublic = Key<Bool>("lastAccountIsPublic", default: false) static let lastAccountIsPublic = Key<Bool>("lastAccountIsPublic", default: false)

View File

@ -42,6 +42,7 @@ struct PlayerSettings: View {
@Default(.captionsDefaultLanguageCode) private var captionsDefaultLanguageCode @Default(.captionsDefaultLanguageCode) private var captionsDefaultLanguageCode
@Default(.captionsFallbackLanguageCode) private var captionsFallbackLanguageCode @Default(.captionsFallbackLanguageCode) private var captionsFallbackLanguageCode
@Default(.captionsFontScaleSize) private var captionsFontScaleSize @Default(.captionsFontScaleSize) private var captionsFontScaleSize
@Default(.captionsFontColor) private var captionsFontColor
@ObservedObject private var accounts = AccountsModel.shared @ObservedObject private var accounts = AccountsModel.shared
@ -111,6 +112,10 @@ struct PlayerSettings: View {
Text("Size").font(.subheadline) Text("Size").font(.subheadline)
#endif #endif
captionsFontScaleSizePicker captionsFontScaleSizePicker
#if os(tvOS)
Text("Color").font(.subheadline)
#endif
captionsFontColorPicker
showCaptionsAutoShowToggle showCaptionsAutoShowToggle
#if !os(tvOS) #if !os(tvOS)
@ -339,12 +344,29 @@ struct PlayerSettings: View {
private var captionsFontScaleSizePicker: some View { private var captionsFontScaleSizePicker: some View {
Picker("Size", selection: $captionsFontScaleSize) { Picker("Size", selection: $captionsFontScaleSize) {
Text("Small").tag(Float(0.5)) Text("Small").tag(String("0.5"))
Text("Medium").tag(Float(1.0)) Text("Medium").tag(String("1.0"))
Text("Large").tag(Float(2.0)) Text("Large").tag(String("2.0"))
} }
.onChange(of: captionsFontScaleSize) { _ in .onChange(of: captionsFontScaleSize) { _ in
PlayerModel.shared.mpvBackend.client.setSubFontSize() PlayerModel.shared.mpvBackend.client.setSubFontSize(scaleSize: captionsFontScaleSize)
}
#if os(macOS)
.labelsHidden()
#endif
}
private var captionsFontColorPicker: some View {
Picker("Color", selection: $captionsFontColor) {
Text("White").tag(String("#FFFFFF"))
Text("Yellow").tag(String("#FFFF00"))
Text("Red").tag(String("#FF0000"))
Text("Orange").tag(String("#FFA500"))
Text("Green").tag(String("#008000"))
Text("Blue").tag(String("#0000FF"))
}
.onChange(of: captionsFontColor) { _ in
PlayerModel.shared.mpvBackend.client.setSubFontColor(color: captionsFontColor)
} }
#if os(macOS) #if os(macOS)
.labelsHidden() .labelsHidden()