1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30

Add rate change selector

This commit is contained in:
Arkadiusz Fal 2022-04-16 22:50:37 +02:00
parent 3f137be780
commit 3953bce8f8
5 changed files with 49 additions and 4 deletions

View File

@ -216,8 +216,8 @@ final class MPVBackend: PlayerBackend {
} }
} }
func setRate(_: Float) { func setRate(_ rate: Float) {
// TODO: Implement rate change client.setDoubleAsync("speed", Double(rate))
} }
func closeItem() {} func closeItem() {}

View File

@ -225,6 +225,11 @@ final class MPVClient: ObservableObject {
mpv_set_property_async(mpv, 0, name, MPV_FORMAT_FLAG, &data) mpv_set_property_async(mpv, 0, name, MPV_FORMAT_FLAG, &data)
} }
func setDoubleAsync(_ name: String, _ value: Double) {
var data = value
mpv_set_property_async(mpv, 0, name, MPV_FORMAT_DOUBLE, &data)
}
private func getDouble(_ name: String) -> Double { private func getDouble(_ name: String) -> Double {
var data = Double() var data = Double()
mpv_get_property(mpv, name, MPV_FORMAT_DOUBLE, &data) mpv_get_property(mpv, name, MPV_FORMAT_DOUBLE, &data)

View File

@ -338,6 +338,7 @@ final class PlayerModel: ObservableObject {
} }
inactiveBackends().forEach { $0.pause() } inactiveBackends().forEach { $0.pause() }
backend.setRate(currentRate)
let fromBackend: PlayerBackend = from == .appleAVPlayer ? avPlayerBackend : mpvBackend let fromBackend: PlayerBackend = from == .appleAVPlayer ? avPlayerBackend : mpvBackend
let toBackend: PlayerBackend = to == .appleAVPlayer ? avPlayerBackend : mpvBackend let toBackend: PlayerBackend = to == .appleAVPlayer ? avPlayerBackend : mpvBackend

View File

@ -122,8 +122,10 @@ enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {
switch self { switch self {
case .best: case .best:
return "Best available quality" return "Best available quality"
case .hd2160p: case .hd2160p60:
return "4K, 60fps" return "4K, 60fps"
case .hd2160p:
return "4K"
default: default:
return value.name return value.name
} }

View File

@ -176,8 +176,10 @@ struct PlayerControls: View {
HStack { HStack {
#if !os(tvOS) #if !os(tvOS)
fullscreenButton fullscreenButton
rateButton
Spacer()
#endif #endif
Spacer()
// button("Music Mode", systemImage: "music.note") // button("Music Mode", systemImage: "music.note")
} }
} }
@ -194,6 +196,41 @@ struct PlayerControls: View {
#endif #endif
} }
private var rateButton: some View {
#if os(macOS)
ratePicker
.labelsHidden()
.frame(maxWidth: 70)
#else
Menu {
ratePicker
.frame(width: 45, height: 30)
#if os(iOS)
.background(VisualEffectBlur(blurStyle: .systemThinMaterial))
#endif
.mask(RoundedRectangle(cornerRadius: 3))
} label: {
Text(player.rateLabel(player.currentRate))
.foregroundColor(.primary)
.frame(maxWidth: .infinity)
}
#endif
}
var ratePicker: some View {
Picker("Rate", selection: rateBinding) {
ForEach(PlayerModel.availableRates, id: \.self) { rate in
Text(player.rateLabel(rate)).tag(rate)
}
}
.transaction { t in t.animation = .none }
}
private var rateBinding: Binding<Float> {
.init(get: { player.currentRate }, set: { rate in player.currentRate = rate })
}
var mediumButtonsBar: some View { var mediumButtonsBar: some View {
HStack { HStack {
#if !os(tvOS) #if !os(tvOS)