1
0
mirror of https://github.com/yattee/yattee.git synced 2025-04-28 07:50:33 +05:30

Merge pull request #636 from stonerl/captions

fix handling and displaying captions
This commit is contained in:
Arkadiusz Fal 2024-05-16 18:18:49 +02:00 committed by GitHub
commit d9aa5105fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 16 deletions

View File

@ -275,6 +275,10 @@ final class MPVBackend: PlayerBackend {
self.startClientUpdates() self.startClientUpdates()
// Captions should only be displayed when selected by the user,
// not when the video starts. So, we remove them.
self.client?.removeSubs()
if !preservingTime, if !preservingTime,
!upgrading, !upgrading,
let segment = self.model.sponsorBlock.segments.first, let segment = self.model.sponsorBlock.segments.first,

View File

@ -176,7 +176,7 @@ final class PlayerModel: ObservableObject {
@Default(.resetWatchedStatusOnPlaying) var resetWatchedStatusOnPlaying @Default(.resetWatchedStatusOnPlaying) var resetWatchedStatusOnPlaying
@Default(.playerRate) var playerRate @Default(.playerRate) var playerRate
@Default(.systemControlsSeekDuration) var systemControlsSeekDuration @Default(.systemControlsSeekDuration) var systemControlsSeekDuration
#if os(macOS) #if os(macOS)
@Default(.buttonBackwardSeekDuration) private var buttonBackwardSeekDuration @Default(.buttonBackwardSeekDuration) private var buttonBackwardSeekDuration
@Default(.buttonForwardSeekDuration) private var buttonForwardSeekDuration @Default(.buttonForwardSeekDuration) private var buttonForwardSeekDuration
@ -192,7 +192,7 @@ final class PlayerModel: ObservableObject {
var onPlayStream = [(Stream) -> Void]() var onPlayStream = [(Stream) -> Void]()
var rateToRestore: Float? var rateToRestore: Float?
private var remoteCommandCenterConfigured = false private var remoteCommandCenterConfigured = false
#if os(macOS) #if os(macOS)
var keyPressMonitor: Any? var keyPressMonitor: Any?
#endif #endif
@ -771,10 +771,12 @@ final class PlayerModel: ObservableObject {
func handleCurrentItemChange() { func handleCurrentItemChange() {
if currentItem == nil { if currentItem == nil {
captions = nil
FeedModel.shared.calculateUnwatchedFeed() FeedModel.shared.calculateUnwatchedFeed()
} }
// Captions need to be set to nil on item change, to clear the previus values.
captions = nil
#if os(macOS) #if os(macOS)
Windows.player.window?.title = windowTitle Windows.player.window?.title = windowTitle
#endif #endif
@ -1158,7 +1160,7 @@ final class PlayerModel: ObservableObject {
return nil return nil
} }
#if os(macOS) #if os(macOS)
private func assignKeyPressMonitor() { private func assignKeyPressMonitor() {
keyPressMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { keyEvent -> NSEvent? in keyPressMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { keyEvent -> NSEvent? in
@ -1188,12 +1190,13 @@ final class PlayerModel: ObservableObject {
if !self.controls.isLoadingVideo { if !self.controls.isLoadingVideo {
self.backend.togglePlay() self.backend.togglePlay()
} }
default: return keyEvent default:
return keyEvent
} }
return nil return nil
} }
} }
private func destroyKeyPressMonitor() { private func destroyKeyPressMonitor() {
if let keyPressMonitor = keyPressMonitor { if let keyPressMonitor = keyPressMonitor {
NSEvent.removeMonitor(keyPressMonitor) NSEvent.removeMonitor(keyPressMonitor)

View File

@ -312,7 +312,6 @@ struct ControlsOverlay: View {
.foregroundColor(.primary) .foregroundColor(.primary)
} }
.transaction { t in t.animation = .none } .transaction { t in t.animation = .none }
.buttonStyle(.plain) .buttonStyle(.plain)
.foregroundColor(.primary) .foregroundColor(.primary)
.frame(width: 240, height: 40) .frame(width: 240, height: 40)
@ -374,12 +373,12 @@ struct ControlsOverlay: View {
let captions = player.currentVideo?.captions ?? [] let captions = player.currentVideo?.captions ?? []
Picker("Captions", selection: captionsBinding) { Picker("Captions", selection: captionsBinding) {
if captions.isEmpty { if captions.isEmpty {
Text("Not available") Text("Not available").tag(Captions?.none)
} else { } else {
Text("Disabled").tag(Captions?.none) Text("Disabled").tag(Captions?.none)
} ForEach(captions) { caption in
ForEach(captions) { caption in Text(caption.description).tag(Optional(caption))
Text(caption.description).tag(Optional(caption)) }
} }
} }
.disabled(captions.isEmpty) .disabled(captions.isEmpty)

View File

@ -433,12 +433,12 @@ struct PlaybackSettings: View {
let captions = player.currentVideo?.captions ?? [] let captions = player.currentVideo?.captions ?? []
Picker("Captions".localized(), selection: $player.captions) { Picker("Captions".localized(), selection: $player.captions) {
if captions.isEmpty { if captions.isEmpty {
Text("Not available") Text("Not available").tag(Captions?.none)
} else { } else {
Text("Disabled").tag(Captions?.none) Text("Disabled").tag(Captions?.none)
} ForEach(captions) { caption in
ForEach(captions) { caption in Text(caption.description).tag(Optional(caption))
Text(caption.description).tag(Optional(caption)) }
} }
} }
.disabled(captions.isEmpty) .disabled(captions.isEmpty)

View File

@ -1,4 +1,3 @@
import SwiftUI import SwiftUI
struct ImportSettings: View { struct ImportSettings: View {