From 66cbfe0a0c76a29d5505aa1ca631fcbb06d21692 Mon Sep 17 00:00:00 2001 From: zackslash Date: Fri, 20 Oct 2023 20:05:13 +0100 Subject: [PATCH] use float value from OS seek --- backend/mpmedia_mac.go | 8 ++++---- backend/mpmediabridge.h | 2 +- backend/mpmediabridge.m | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/mpmedia_mac.go b/backend/mpmedia_mac.go index fc2914d..7848856 100644 --- a/backend/mpmedia_mac.go +++ b/backend/mpmedia_mac.go @@ -27,7 +27,7 @@ import ( // os_remote_command_callback is called by Objective-C when incoming OS media commands are received. // //export os_remote_command_callback -func os_remote_command_callback(command C.Command, value C.int) { +func os_remote_command_callback(command C.Command, value C.double) { switch command { case C.PLAY: mpMediaEventRecipient.OnCommandPlay() @@ -42,7 +42,7 @@ func os_remote_command_callback(command C.Command, value C.int) { case C.NEXT_TRACK: mpMediaEventRecipient.OnCommandNextTrack() case C.SEEK: - mpMediaEventRecipient.OnCommandSeek(int(value)) + mpMediaEventRecipient.OnCommandSeek(float64(value)) default: log.Printf("unknown OS command received: %v", command) } @@ -172,9 +172,9 @@ func (mp *MPMediaHandler) OnCommandPreviousTrack() { } // MPMediaHandler instance received OS command to 'seek' -func (mp *MPMediaHandler) OnCommandSeek(positionSeconds int) { +func (mp *MPMediaHandler) OnCommandSeek(positionSeconds float64) { if mp == nil || mp.player == nil { return } - mp.player.Seek(fmt.Sprintf("%d", positionSeconds), player.SeekAbsolute) + mp.player.Seek(fmt.Sprintf("%0.2f", positionSeconds), player.SeekAbsolute) } diff --git a/backend/mpmediabridge.h b/backend/mpmediabridge.h index 9e9aac7..3eaa75d 100644 --- a/backend/mpmediabridge.h +++ b/backend/mpmediabridge.h @@ -33,7 +33,7 @@ void register_os_remote_commands(); * Go-backed callback to static function that is called when OS remote commands are received. * If a value is anticipated with the specified command, the 'value' argument will be non-zero. */ -void os_remote_command_callback(Command command, int value); +void os_remote_command_callback(Command command, double value); /** * Updates the "Now Playing" information on macOS for media playback diff --git a/backend/mpmediabridge.m b/backend/mpmediabridge.m index bfe17e7..1e01530 100644 --- a/backend/mpmediabridge.m +++ b/backend/mpmediabridge.m @@ -39,9 +39,7 @@ void register_os_remote_commands() { [commandCenter.changePlaybackPositionCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) { MPChangePlaybackPositionCommandEvent *positionChangeEvent = (MPChangePlaybackPositionCommandEvent *)event; - double posSecDouble = positionChangeEvent.positionTime; - int posSeconds = (int)posSecDouble; - os_remote_command_callback(SEEK, posSeconds); + os_remote_command_callback(SEEK, positionChangeEvent.positionTime); return MPRemoteCommandHandlerStatusSuccess; }]; }