From 9c0716c7c2492fdcf10d58680aa31645bb29ced5 Mon Sep 17 00:00:00 2001 From: lovegaoshi <106490582+lovegaoshi@users.noreply.github.com> Date: Wed, 25 Oct 2023 07:58:42 -0700 Subject: [PATCH] fix: no playsong logic I wrapped SongInfo's playSong into a wrapper. within the wrapper useActiveTrack().song is correct as the previous song, but then in playSong useActiveTrack().song is the scheduled next song. This sounds like a serious bug but oh well. --- src/hooks/usePlayback.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hooks/usePlayback.ts b/src/hooks/usePlayback.ts index 703b43908..44a06a751 100644 --- a/src/hooks/usePlayback.ts +++ b/src/hooks/usePlayback.ts @@ -3,7 +3,6 @@ import { useEffect, useState } from 'react'; import TrackPlayer, { Event, State, - useActiveTrack, RepeatMode, } from 'react-native-track-player'; import { useTranslation } from 'react-i18next'; @@ -40,11 +39,11 @@ const usePlayback = () => { const { t } = useTranslation(); const currentPlayingList = useNoxSetting(state => state.currentPlayingList); const playlists = useNoxSetting(state => state.playlists); + const currentPlayingId = useNoxSetting(state => state.currentPlayingId); const setCurrentPlayingId = useNoxSetting(state => state.setCurrentPlayingId); const setCurrentPlayingList = useNoxSetting( state => state.setCurrentPlayingList ); - const track = useActiveTrack(); const netInfo = useNetInfo(); const playerSetting = useNoxSetting(state => state.playerSetting); @@ -81,10 +80,12 @@ const usePlayback = () => { song = randomChoice(playlist.songList); } } - setCurrentPlayingId(song.id); - if (!interruption && track?.song?.id === song.id) { + // HACK: track?.song? is somehow updated already here + // TODO: fix this + if (!interruption && currentPlayingId === song.id) { clearPlaylistUninterrupted(); } else { + setCurrentPlayingId(song.id); await TrackPlayer.reset(); await TrackPlayer.add(await songlistToTracklist([song])); TrackPlayer.play();