Extend MPMedia implementation to handle 'seek'

This commit is contained in:
zackslash
2023-10-20 18:04:05 +01:00
parent 6aeaf07611
commit cc85b79f79
3 changed files with 53 additions and 13 deletions
+19 -2
View File
@@ -16,6 +16,7 @@ import (
)
import (
"fmt"
"log"
"unsafe"
@@ -26,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) {
func os_remote_command_callback(command C.Command, value C.int) {
switch command {
case C.PLAY:
mpMediaEventRecipient.OnCommandPlay()
@@ -40,6 +41,8 @@ func os_remote_command_callback(command C.Command) {
mpMediaEventRecipient.OnCommandPreviousTrack()
case C.NEXT_TRACK:
mpMediaEventRecipient.OnCommandNextTrack()
case C.SEEK:
mpMediaEventRecipient.OnCommandSeek(int(value))
default:
log.Printf("unknown OS command received: %v", command)
}
@@ -85,7 +88,9 @@ func NewMPMediaHandler(player *player.Player, playbackManager *PlaybackManager)
cArtURL := C.CString(artURL)
defer C.free(unsafe.Pointer(cArtURL))
C.set_os_now_playing_info(cTitle, cArtist, cArtURL)
cTrackDuration := C.double(track.Duration)
C.set_os_now_playing_info(cTitle, cArtist, cArtURL, cTrackDuration)
}
})
@@ -101,6 +106,10 @@ func NewMPMediaHandler(player *player.Player, playbackManager *PlaybackManager)
C.set_os_playback_state_paused()
})
mp.player.OnSeek(func() {
C.update_os_now_playing_info_position(C.double(mp.player.GetStatus().TimePos))
})
return mp
}
@@ -159,3 +168,11 @@ func (mp *MPMediaHandler) OnCommandPreviousTrack() {
}
mp.player.SeekBackOrPrevious()
}
// MPMediaHandler instance received OS command to 'seek'
func (mp *MPMediaHandler) OnCommandSeek(positionSeconds int) {
if mp == nil || mp.player == nil {
return
}
mp.player.Seek(fmt.Sprintf("%d", positionSeconds), player.SeekAbsolute)
}