diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 17e1e721..1b0267dc 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -52,7 +52,7 @@ extension PlayerModel { savedTime = currentItem.playbackTime loadAvailableStreams(currentVideo!) { streams in - guard let stream = streams.first else { + guard let stream = self.preferredStream(streams) else { return } @@ -65,6 +65,14 @@ extension PlayerModel { } } + private func preferredStream(_ streams: [Stream]) -> Stream? { + if let id = Defaults[.playerInstanceID] { + return streams.first { $0.instance.id == id } + } else { + return streams.first + } + } + func advanceToNextItem() { addCurrentItemToHistory() diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 72c4e175..a18e7ca2 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -53,6 +53,7 @@ extension Defaults.Keys { static let quality = Key("quality", default: .hd720pFirstThenBest) static let playerSidebar = Key("playerSidebar", default: PlayerSidebarSetting.defaultValue) + static let playerInstanceID = Key("playerInstance") static let showKeywords = Key("showKeywords", default: false) static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: []) diff --git a/Shared/Settings/PlaybackSettings.swift b/Shared/Settings/PlaybackSettings.swift index ff241925..3fd74714 100644 --- a/Shared/Settings/PlaybackSettings.swift +++ b/Shared/Settings/PlaybackSettings.swift @@ -2,6 +2,8 @@ import Defaults import SwiftUI struct PlaybackSettings: View { + @Default(.instances) private var instances + @Default(.playerInstanceID) private var playerInstanceID @Default(.quality) private var quality @Default(.playerSidebar) private var playerSidebar @Default(.showKeywords) private var showKeywords @@ -13,6 +15,8 @@ struct PlaybackSettings: View { #endif var body: some View { + playerInstanceSection + qualitySection #if !os(tvOS) @@ -24,6 +28,24 @@ struct PlaybackSettings: View { #endif } + private var playerInstanceSection: some View { + Section(header: Text("Preferred playback source")) { + Picker("Source", selection: $playerInstanceID) { + Text("Best available stream").tag(String?.none) + + ForEach(instances) { instance in + Text(instance.longDescription).tag(Optional(instance.id)) + } + } + .labelsHidden() + #if os(iOS) + .pickerStyle(.automatic) + #elseif os(tvOS) + .pickerStyle(.inline) + #endif + } + } + private var qualitySection: some View { Section(header: Text("Quality")) { Picker("Quality", selection: $quality) {