diff --git a/Model/Player/Backends/MPVClient.swift b/Model/Player/Backends/MPVClient.swift index 44ff0f84..f3572b67 100644 --- a/Model/Player/Backends/MPVClient.swift +++ b/Model/Player/Backends/MPVClient.swift @@ -1,4 +1,5 @@ import CoreMedia +import Defaults import Foundation import Logging #if !os(macOS) @@ -46,8 +47,8 @@ final class MPVClient: ObservableObject { #endif checkError(mpv_set_option_string(mpv, "cache-pause-initial", "yes")) - checkError(mpv_set_option_string(mpv, "cache-secs", "20")) - checkError(mpv_set_option_string(mpv, "cache-pause-wait", "2")) + checkError(mpv_set_option_string(mpv, "cache-secs", Defaults[.mpvCacheSecs])) + checkError(mpv_set_option_string(mpv, "cache-pause-wait", Defaults[.mpvCachePauseWait])) checkError(mpv_set_option_string(mpv, "keep-open", "yes")) checkError(mpv_set_option_string(mpv, "hwdec", machine == "x86_64" ? "no" : "auto-safe")) checkError(mpv_set_option_string(mpv, "vo", "libmpv")) diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index e35857e3..3920d228 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -96,6 +96,9 @@ extension Defaults.Keys { static let showMPVPlaybackStats = Key("showMPVPlaybackStats", default: false) static let playerDetailsPageButtonLabelStyle = Key("playerDetailsPageButtonLabelStyle", default: defaultForPlayerDetailsPageButtonLabelStyle) + + static let mpvCacheSecs = Key("mpvCacheSecs", default: "20") + static let mpvCachePauseWait = Key("mpvCachePauseWait", default: "2") } enum ResolutionSetting: String, CaseIterable, Defaults.Serializable { diff --git a/Shared/Settings/AdvancedSettings.swift b/Shared/Settings/AdvancedSettings.swift index ce5a08cb..74e2e348 100644 --- a/Shared/Settings/AdvancedSettings.swift +++ b/Shared/Settings/AdvancedSettings.swift @@ -4,6 +4,8 @@ import SwiftUI struct AdvancedSettings: View { @Default(.instancesManifest) private var instancesManifest @Default(.showMPVPlaybackStats) private var showMPVPlaybackStats + @Default(.mpvCacheSecs) private var mpvCacheSecs + @Default(.mpvCachePauseWait) private var mpvCachePauseWait var body: some View { VStack(alignment: .leading) { @@ -26,27 +28,54 @@ struct AdvancedSettings: View { } @ViewBuilder var advancedSettings: some View { - Section(header: manifestHeader, footer: manifestFooter) { + Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) { + showMPVPlaybackStatsToggle + + HStack { + Text("cache-secs") + #if os(macOS) + .frame(minWidth: 120, alignment: .leading) + #endif + TextField("cache-secs", text: $mpvCacheSecs) + } + + HStack { + Text("cache-pause-wait") + #if os(macOS) + .frame(minWidth: 120, alignment: .leading) + #endif + TextField("cache-pause-wait", text: $mpvCachePauseWait) + } + } + .multilineTextAlignment(.trailing) + + Section(header: manifestHeader) { TextField("URL", text: $instancesManifest) + #if !os(macOS) + .keyboardType(.webSearch) + #endif + .disableAutocorrection(true) } .padding(.bottom, 4) + } - Section(header: SettingsHeader(text: "Debugging")) { - showMPVPlaybackStatsToggle + @ViewBuilder var mpvFooter: some View { + VStack(alignment: .leading) { + Text("Restart the app to apply the settings above.") + HStack(spacing: 2) { + Text("More info can be found in") + Link("MPV Documentation", destination: URL(string: "https://mpv.io/manual/master")!) + } } + .foregroundColor(.secondary) } var manifestHeader: some View { SettingsHeader(text: "Public Manifest") } - var manifestFooter: some View { - Text("You can create your own locations manifest and set its URL here to replace the built-in one") - .foregroundColor(.secondary) - } - var showMPVPlaybackStatsToggle: some View { - Toggle("Show MPV playback statistics", isOn: $showMPVPlaybackStats) + Toggle("Show playback statistics", isOn: $showMPVPlaybackStats) } }