From 0a343369bad108e7a2267345adb71aa8687a4ddb Mon Sep 17 00:00:00 2001 From: der richter Date: Thu, 8 Feb 2024 01:05:25 +0100 Subject: [PATCH] mac/remote: add playback rate info also rate limit the position to update at max once per second. --- osdep/macos/remote_command_center.swift | 7 +++++-- osdep/macosx_events.m | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/osdep/macos/remote_command_center.swift b/osdep/macos/remote_command_center.swift index e3060516ed..4eb112d936 100644 --- a/osdep/macos/remote_command_center.swift +++ b/osdep/macos/remote_command_center.swift @@ -46,6 +46,7 @@ class RemoteCommandCenter: NSObject { var isPaused: Bool = false { didSet { updateInfoCenter() } } var duration: Double = 0 { didSet { updateInfoCenter() } } var position: Double = 0 { didSet { updateInfoCenter() } } + var rate: Double = 0 { didSet { updateInfoCenter() } } var infoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } } var commandCenter: MPRemoteCommandCenter { get { return MPRemoteCommandCenter.shared() } } @@ -139,7 +140,7 @@ class RemoteCommandCenter: NSObject { func updateInfoCenter() { nowPlayingInfo.merge([ - MPNowPlayingInfoPropertyPlaybackRate: NSNumber(value: !isPaused), + MPNowPlayingInfoPropertyPlaybackRate: NSNumber(value: isPaused ? 0 : rate), MPNowPlayingInfoPropertyElapsedPlaybackTime: NSNumber(value: position), MPMediaItemPropertyPlaybackDuration: NSNumber(value: duration), ]) { (_, new) in new } @@ -184,11 +185,13 @@ class RemoteCommandCenter: NSObject { isPaused = LibmpvHelper.mpvFlagToBool(property.data) ?? false case "time-pos" where property.format == MPV_FORMAT_DOUBLE: let newPosition = max(LibmpvHelper.mpvDoubleToDouble(property.data) ?? 0, 0) - if Int(floor(newPosition) - floor(position)) != 0 { + if Int((floor(newPosition) - floor(position)) / rate) != 0 { position = newPosition } case "duration" where property.format == MPV_FORMAT_DOUBLE: duration = LibmpvHelper.mpvDoubleToDouble(property.data) ?? 0 + case "speed" where property.format == MPV_FORMAT_DOUBLE: + rate = LibmpvHelper.mpvDoubleToDouble(property.data) ?? 1 default: break } diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 33ea265797..6ffff3d161 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -156,6 +156,7 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) if ([[EventsResponder sharedInstance] setMpvHandle:ctx]) { mpv_observe_property(ctx, 0, "duration", MPV_FORMAT_DOUBLE); mpv_observe_property(ctx, 0, "time-pos", MPV_FORMAT_DOUBLE); + mpv_observe_property(ctx, 0, "speed", MPV_FORMAT_DOUBLE); mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG); mpv_set_wakeup_callback(ctx, wakeup, NULL); }