Add "Always use AVPlayer for live videos" option

This commit is contained in:
Arkadiusz Fal 2022-08-22 23:14:27 +02:00
parent e4c6fd8c9e
commit 868883dc45
3 changed files with 20 additions and 7 deletions

View File

@ -158,6 +158,7 @@ final class PlayerModel: ObservableObject {
}} }}
@Default(.qualityProfiles) var qualityProfiles @Default(.qualityProfiles) var qualityProfiles
@Default(.forceAVPlayerForLiveStreams) var forceAVPlayerForLiveStreams
@Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer
@Default(.closePiPOnNavigation) var closePiPOnNavigation @Default(.closePiPOnNavigation) var closePiPOnNavigation
@Default(.closePiPOnOpeningPlayer) var closePiPOnOpeningPlayer @Default(.closePiPOnOpeningPlayer) var closePiPOnOpeningPlayer
@ -344,9 +345,10 @@ final class PlayerModel: ObservableObject {
var changeBackendHandler: (() -> Void)? var changeBackendHandler: (() -> Void)?
if let backend = qualityProfile?.backend ?? QualityProfilesModel.shared.automaticProfile?.backend, if let backend = (live && forceAVPlayerForLiveStreams) ? PlayerBackendType.appleAVPlayer :
activeBackend != backend, (qualityProfile?.backend ?? QualityProfilesModel.shared.automaticProfile?.backend),
backend == .appleAVPlayer || !avPlayerBackend.startPictureInPictureOnPlay activeBackend != backend,
backend == .appleAVPlayer || !avPlayerBackend.startPictureInPictureOnPlay
{ {
changeBackendHandler = { [weak self] in changeBackendHandler = { [weak self] in
guard let self = self else { return } guard let self = self else { return }
@ -446,10 +448,11 @@ final class PlayerModel: ObservableObject {
return return
} }
if let qualityProfileBackend = qualityProfile?.backend, qualityProfileBackend != activeBackend, if let backend = (live && forceAVPlayerForLiveStreams) ? PlayerBackendType.appleAVPlayer : qualityProfile?.backend,
qualityProfileBackend == .appleAVPlayer || !(avPlayerBackend.startPictureInPictureOnPlay || playingInPictureInPicture) backend != activeBackend,
backend == .appleAVPlayer || !(avPlayerBackend.startPictureInPictureOnPlay || playingInPictureInPicture)
{ {
changeActiveBackend(from: activeBackend, to: qualityProfileBackend) changeActiveBackend(from: activeBackend, to: backend)
} }
guard let stream = streamByQualityProfile else { guard let stream = streamByQualityProfile else {
@ -502,6 +505,8 @@ final class PlayerModel: ObservableObject {
return return
} }
logger.info("changing backend from \(from.rawValue) to \(to.rawValue)")
pause() pause()
if to == .mpv { if to == .mpv {

View File

@ -87,6 +87,7 @@ extension Defaults.Keys {
static let batteryNonCellularProfile = Key<QualityProfile.ID>("batteryNonCellularProfile", default: batteryNonCellularProfileDefault) static let batteryNonCellularProfile = Key<QualityProfile.ID>("batteryNonCellularProfile", default: batteryNonCellularProfileDefault)
static let chargingCellularProfile = Key<QualityProfile.ID>("chargingCellularProfile", default: chargingCellularProfileDefault) static let chargingCellularProfile = Key<QualityProfile.ID>("chargingCellularProfile", default: chargingCellularProfileDefault)
static let chargingNonCellularProfile = Key<QualityProfile.ID>("chargingNonCellularProfile", default: chargingNonCellularProfileDefault) static let chargingNonCellularProfile = Key<QualityProfile.ID>("chargingNonCellularProfile", default: chargingNonCellularProfileDefault)
static let forceAVPlayerForLiveStreams = Key<Bool>("forceAVPlayerForLiveStreams", default: true)
static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: PlayerSidebarSetting.defaultValue) static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: PlayerSidebarSetting.defaultValue)
static let playerInstanceID = Key<Instance.ID?>("playerInstance") static let playerInstanceID = Key<Instance.ID?>("playerInstance")

View File

@ -12,9 +12,10 @@ struct QualitySettings: View {
@Default(.batteryNonCellularProfile) private var batteryNonCellularProfile @Default(.batteryNonCellularProfile) private var batteryNonCellularProfile
@Default(.chargingCellularProfile) private var chargingCellularProfile @Default(.chargingCellularProfile) private var chargingCellularProfile
@Default(.chargingNonCellularProfile) private var chargingNonCellularProfile @Default(.chargingNonCellularProfile) private var chargingNonCellularProfile
@Default(.forceAVPlayerForLiveStreams) private var forceAVPlayerForLiveStreams
var body: some View { var body: some View {
VStack { VStack(alignment: .leading) {
#if os(macOS) #if os(macOS)
sections sections
@ -63,6 +64,8 @@ struct QualitySettings: View {
Picker("Default", selection: $chargingNonCellularProfile) { profilePickerOptions } Picker("Default", selection: $chargingNonCellularProfile) { profilePickerOptions }
} }
#endif #endif
forceAVPlayerForLiveStreamsToggle
} }
.disabled(qualityProfiles.isEmpty) .disabled(qualityProfiles.isEmpty)
Section(header: SettingsHeader(text: "Profiles"), footer: profilesFooter) { Section(header: SettingsHeader(text: "Profiles"), footer: profilesFooter) {
@ -103,6 +106,10 @@ struct QualitySettings: View {
Picker("Charging", selection: $chargingNonCellularProfile) { profilePickerOptions } Picker("Charging", selection: $chargingNonCellularProfile) { profilePickerOptions }
} }
@ViewBuilder var forceAVPlayerForLiveStreamsToggle: some View {
Toggle("Always use AVPlayer for live videos", isOn: $forceAVPlayerForLiveStreams)
}
@ViewBuilder func profileControl(_ qualityProfile: QualityProfile) -> some View { @ViewBuilder func profileControl(_ qualityProfile: QualityProfile) -> some View {
#if os(tvOS) #if os(tvOS)
Button { Button {