improvements to captions on tvOS

This commit is contained in:
Toni Förster 2024-05-20 14:20:08 +02:00
parent 4db02b2638
commit c9125644ed
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
3 changed files with 207 additions and 136 deletions

View File

@ -333,9 +333,19 @@ struct ControlsOverlay: View {
} label: { } label: {
HStack(spacing: 4) { HStack(spacing: 4) {
Image(systemName: "text.bubble") Image(systemName: "text.bubble")
if let captions = captionsBinding.wrappedValue { if let captions = captionsBinding.wrappedValue,
Text(captions.code) let language = LanguageCodes(rawValue: captions.code)
.foregroundColor(.primary)
{
Text("\(language.description.capitalized) (\(language.rawValue))")
.foregroundColor(.accentColor)
} else {
if captionsBinding.wrappedValue == nil {
Text("Not available")
} else {
Text("Disabled")
.foregroundColor(.accentColor)
}
} }
} }
.frame(width: 240) .frame(width: 240)
@ -351,8 +361,18 @@ struct ControlsOverlay: View {
ControlsOverlayButton(focusedField: $focusedField, field: .captions) { ControlsOverlayButton(focusedField: $focusedField, field: .captions) {
HStack(spacing: 8) { HStack(spacing: 8) {
Image(systemName: "text.bubble") Image(systemName: "text.bubble")
if let captions = captionsBinding.wrappedValue { if let captions = captionsBinding.wrappedValue,
Text(captions.code) let language = LanguageCodes(rawValue: captions.code)
{
Text("\(language.description.capitalized) (\(language.rawValue))")
.foregroundColor(.accentColor)
} else {
if captionsBinding.wrappedValue == nil {
Text("Not available")
} else {
Text("Disabled")
.foregroundColor(.accentColor)
}
} }
} }
.frame(maxWidth: 320) .frame(maxWidth: 320)

View File

@ -384,13 +384,16 @@ struct PlaybackSettings: View {
} }
@ViewBuilder private var captionsButton: some View { @ViewBuilder private var captionsButton: some View {
let videoCaptions = player.currentVideo?.captions
#if os(macOS) #if os(macOS)
captionsPicker captionsPicker
.labelsHidden() .labelsHidden()
.frame(maxWidth: 300) .frame(maxWidth: 300)
#elseif os(iOS) #elseif os(iOS)
Menu { Menu {
if videoCaptions?.isEmpty == false {
captionsPicker captionsPicker
}
} label: { } label: {
HStack(spacing: 4) { HStack(spacing: 4) {
Image(systemName: "text.bubble") Image(systemName: "text.bubble")
@ -399,10 +402,17 @@ struct PlaybackSettings: View {
{ {
Text("\(language.description.capitalized) (\(language.rawValue))") Text("\(language.description.capitalized) (\(language.rawValue))")
.foregroundColor(.accentColor) .foregroundColor(.accentColor)
} else {
if videoCaptions?.isEmpty == true {
Text("Not available")
} else {
Text("Disabled")
}
} }
} }
.frame(alignment: .trailing) .frame(alignment: .trailing)
.frame(height: 40) .frame(height: 40)
.disabled(videoCaptions?.isEmpty == true)
} }
.transaction { t in t.animation = .none } .transaction { t in t.animation = .none }
.buttonStyle(.plain) .buttonStyle(.plain)

View File

@ -49,6 +49,10 @@ struct PlayerSettings: View {
} }
#endif #endif
#if os(tvOS)
@State private var isShowingLanguagePicker = false
#endif
var body: some View { var body: some View {
Group { Group {
#if os(macOS) #if os(macOS)
@ -101,7 +105,23 @@ struct PlayerSettings: View {
Section(header: SettingsHeader(text: "Captions".localized())) { Section(header: SettingsHeader(text: "Captions".localized())) {
showCaptionsAutoShowToggle showCaptionsAutoShowToggle
#if !os(tvOS)
captionDefaultLanguagePicker captionDefaultLanguagePicker
#else
Button(action: { isShowingLanguagePicker = true }) {
HStack {
Text("Default language")
Spacer()
Text("\(LanguageCodes(rawValue: captionsDefaultLanguageCode)!.description.capitalized) (\(captionsDefaultLanguageCode))").foregroundColor(.secondary)
}
}
.frame(maxWidth: .infinity).sheet(isPresented: $isShowingLanguagePicker) {
LanguagePickerTVOS(
selectedLanguage: $captionsDefaultLanguageCode,
isShowing: $isShowingLanguagePicker
)
}
#endif
} }
#if !os(tvOS) #if !os(tvOS)
@ -290,21 +310,11 @@ struct PlayerSettings: View {
} }
#endif #endif
#if !os(tvOS)
private var inspectorVisibilityPicker: some View {
Picker("Inspector", selection: $showInspector) {
Text("Always").tag(ShowInspectorSetting.always)
Text("Only for local files and URLs").tag(ShowInspectorSetting.onlyLocal)
}
#if os(macOS)
.labelsHidden()
#endif
}
private var showCaptionsAutoShowToggle: some View { private var showCaptionsAutoShowToggle: some View {
Toggle("Always show captions", isOn: $captionsAutoShow) Toggle("Always show captions", isOn: $captionsAutoShow)
} }
#if !os(tvOS)
private var captionDefaultLanguagePicker: some View { private var captionDefaultLanguagePicker: some View {
Picker("Default language", selection: $captionsDefaultLanguageCode) { Picker("Default language", selection: $captionsDefaultLanguageCode) {
ForEach(LanguageCodes.allCases, id: \.self) { language in ForEach(LanguageCodes.allCases, id: \.self) { language in
@ -315,6 +325,37 @@ struct PlayerSettings: View {
.labelsHidden() .labelsHidden()
#endif #endif
} }
#else
struct LanguagePickerTVOS: View {
@Binding var selectedLanguage: String
@Binding var isShowing: Bool
var body: some View {
NavigationView {
List(LanguageCodes.allCases, id: \.self) { language in
Button(action: {
selectedLanguage = language.rawValue
isShowing = false
}) {
Text("\(language.description.capitalized) (\(language.rawValue))")
}
}
.navigationTitle("Select Default Language")
}
}
}
#endif
#if !os(tvOS)
private var inspectorVisibilityPicker: some View {
Picker("Inspector", selection: $showInspector) {
Text("Always").tag(ShowInspectorSetting.always)
Text("Only for local files and URLs").tag(ShowInspectorSetting.onlyLocal)
}
#if os(macOS)
.labelsHidden()
#endif
}
private var showChaptersToggle: some View { private var showChaptersToggle: some View {
Toggle("Show chapters", isOn: $showChapters) Toggle("Show chapters", isOn: $showChapters)