Default player instance setting

This commit is contained in:
Arkadiusz Fal 2021-11-04 00:40:01 +01:00
parent 2fcbe94e6f
commit 505fbdbc51
3 changed files with 32 additions and 1 deletions

View File

@ -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()

View File

@ -53,6 +53,7 @@ extension Defaults.Keys {
static let quality = Key<Stream.ResolutionSetting>("quality", default: .hd720pFirstThenBest)
static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: PlayerSidebarSetting.defaultValue)
static let playerInstanceID = Key<Instance.ID?>("playerInstance")
static let showKeywords = Key<Bool>("showKeywords", default: false)
static let recentlyOpened = Key<[RecentItem]>("recentlyOpened", default: [])

View File

@ -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) {