Skip to content

Commit

Permalink
Merge pull request #541 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: last played duration
  • Loading branch information
lovegaoshi authored Aug 29, 2024
2 parents a111a1f + 64cd5ac commit c036ab5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/hooks/useSetupPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default ({ intentData }: NoxComponent.AppProps) => {
noInterruption: storedPlayerSetting.noInterruption,
keepForeground: storedPlayerSetting.keepForeground,
lastPlayDuration,
currentPlayingID,
};
await SetupService(serviceOptions);
initializePlaybackMode(playbackMode);
Expand Down
13 changes: 8 additions & 5 deletions src/services/PlaybackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const lastPlayedDuration: { val?: number } = { val: 0 };
export async function AdditionalPlaybackService({
noInterruption = false,
lastPlayDuration,
currentPlayingID,
}: Partial<NoxStorage.PlayerSettingDict>) {
TrackPlayer.addEventListener(Event.RemoteDuck, async event => {
console.log('Event.RemoteDuck', event);
Expand All @@ -39,12 +40,14 @@ export async function AdditionalPlaybackService({
});

lastPlayedDuration.val = lastPlayDuration;
TrackPlayer.addEventListener(Event.PlaybackState, event => {
TrackPlayer.addEventListener(Event.PlaybackState, async event => {
if (lastPlayedDuration.val && event.state === State.Ready) {
logger.debug(
`[Playback] initalized last played duration to ${lastPlayDuration}`
);
TrackPlayer.seekTo(lastPlayedDuration.val);
if ((await TrackPlayer.getActiveTrack())?.song?.id === currentPlayingID) {
logger.debug(
`[Playback] initalized last played duration to ${lastPlayDuration}`
);
TrackPlayer.seekTo(lastPlayedDuration.val);
}
lastPlayedDuration.val = undefined;
}
});
Expand Down

0 comments on commit c036ab5

Please sign in to comment.