Add MPV cache advanced settings

This commit is contained in:
Arkadiusz Fal 2022-07-02 12:49:57 +02:00
parent 394980fe73
commit 41fb021b64
3 changed files with 44 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import CoreMedia import CoreMedia
import Defaults
import Foundation import Foundation
import Logging import Logging
#if !os(macOS) #if !os(macOS)
@ -46,8 +47,8 @@ final class MPVClient: ObservableObject {
#endif #endif
checkError(mpv_set_option_string(mpv, "cache-pause-initial", "yes")) 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-secs", Defaults[.mpvCacheSecs]))
checkError(mpv_set_option_string(mpv, "cache-pause-wait", "2")) 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, "keep-open", "yes"))
checkError(mpv_set_option_string(mpv, "hwdec", machine == "x86_64" ? "no" : "auto-safe")) checkError(mpv_set_option_string(mpv, "hwdec", machine == "x86_64" ? "no" : "auto-safe"))
checkError(mpv_set_option_string(mpv, "vo", "libmpv")) checkError(mpv_set_option_string(mpv, "vo", "libmpv"))

View File

@ -96,6 +96,9 @@ extension Defaults.Keys {
static let showMPVPlaybackStats = Key<Bool>("showMPVPlaybackStats", default: false) static let showMPVPlaybackStats = Key<Bool>("showMPVPlaybackStats", default: false)
static let playerDetailsPageButtonLabelStyle = Key<PlayerDetailsPageButtonLabelStyle>("playerDetailsPageButtonLabelStyle", default: defaultForPlayerDetailsPageButtonLabelStyle) static let playerDetailsPageButtonLabelStyle = Key<PlayerDetailsPageButtonLabelStyle>("playerDetailsPageButtonLabelStyle", default: defaultForPlayerDetailsPageButtonLabelStyle)
static let mpvCacheSecs = Key<String>("mpvCacheSecs", default: "20")
static let mpvCachePauseWait = Key<String>("mpvCachePauseWait", default: "2")
} }
enum ResolutionSetting: String, CaseIterable, Defaults.Serializable { enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {

View File

@ -4,6 +4,8 @@ import SwiftUI
struct AdvancedSettings: View { struct AdvancedSettings: View {
@Default(.instancesManifest) private var instancesManifest @Default(.instancesManifest) private var instancesManifest
@Default(.showMPVPlaybackStats) private var showMPVPlaybackStats @Default(.showMPVPlaybackStats) private var showMPVPlaybackStats
@Default(.mpvCacheSecs) private var mpvCacheSecs
@Default(.mpvCachePauseWait) private var mpvCachePauseWait
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
@ -26,27 +28,54 @@ struct AdvancedSettings: View {
} }
@ViewBuilder var advancedSettings: some 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) TextField("URL", text: $instancesManifest)
#if !os(macOS)
.keyboardType(.webSearch)
#endif
.disableAutocorrection(true)
} }
.padding(.bottom, 4) .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 { var manifestHeader: some View {
SettingsHeader(text: "Public Manifest") 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 { var showMPVPlaybackStatsToggle: some View {
Toggle("Show MPV playback statistics", isOn: $showMPVPlaybackStats) Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
} }
} }