Skip to content

Commit

Permalink
HELL YEAH: reimplement seeking from the media session
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshankman committed Nov 18, 2024
1 parent 9bb062a commit f0f11aa
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/renderer/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default function Main() {
const setFilteredLibrary = useMainStore((store) => store.setFilteredLibrary);
const selectSpecificSong = useMainStore((store) => store.selectSpecificSong);
const setCurrentSongTime = useMainStore((store) => store.setCurrentSongTime);
const currentSongTime = useMainStore((store) => store.currentSongTime);
const currentSongMetadata = useMainStore(
(store) => store.currentSongMetadata,
);
const setOverrideScrollToIndex = useMainStore(
(store) => store.setOverrideScrollToIndex,
);
Expand Down Expand Up @@ -247,12 +251,29 @@ export default function Main() {
setPaused(true);
document.querySelector('audio')?.pause();
});
navigator.mediaSession.setActionHandler('seekto', (seekDetails) => {
setCurrentSongTime(seekDetails.seekTime || 0);
player.setPosition((seekDetails.seekTime || 0) * 1000);
});

// Get the current song's duration from metadata
const duration = currentSongMetadata?.format?.duration || 0;

navigator.mediaSession.setPositionState({
duration: 0,
duration,
playbackRate: 1,
position: 0,
position: currentSongTime,
});
}, [paused, skipToNextSong, playPreviousSong, setPaused]);
}, [
paused,
skipToNextSong,
playPreviousSong,
setPaused,
currentSongTime,
currentSongMetadata,
player,
setCurrentSongTime,
]);

/**
* @important this handles requesting the play count to be incremented.
Expand Down

0 comments on commit f0f11aa

Please sign in to comment.