Skip to content

Commit

Permalink
fix: no playsong logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lovegaoshi committed Oct 25, 2023
1 parent d3b47a9 commit 9c0716c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/hooks/usePlayback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9c0716c

Please sign in to comment.