Browse Source

Fix when play/pause after scrobble threshold (#30)

master
jeffvli 3 years ago
committed by Jeff
parent
commit
42eddb563c
  1. 56
      src/components/player/Player.tsx

56
src/components/player/Player.tsx

@ -467,24 +467,48 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
); );
}, [dispatch, playQueue, scrobbled]); }, [dispatch, playQueue, scrobbled]);
const handleOnPlay = (playerNumber: 1 | 2) => { const handleOnPlay = useCallback(
setScrobbled(false); (playerNumber: 1 | 2) => {
if (playQueue.scrobble) { // Don't run this if resuming a song, so we'll use a 30 second check
if (playerNumber === 1) { if (playQueue.scrobble) {
if (playQueue[currentEntryList][playQueue.player1.index]?.id) { let fadeAtTime;
scrobble({ let duration;
id: playQueue[currentEntryList][playQueue.player1.index]?.id, if (playQueue.currentPlayer === 1) {
submission: false, duration = player1Ref.current.audioEl.current?.duration;
}); fadeAtTime = duration - playQueue.fadeDuration;
} else {
duration = player2Ref.current.audioEl.current?.duration;
fadeAtTime = duration - playQueue.fadeDuration;
}
// Set the reset scrobble condition based on fade or gapless
if (
playQueue.fadeDuration > 0
? !(player.currentSeek >= 240 || player.currentSeek >= fadeAtTime - 15) &&
player.currentSeek <= fadeAtTime
: !(player.currentSeek >= 240 || player.currentSeek >= duration * 0.9)
) {
setScrobbled(false);
if (playQueue.scrobble) {
if (playerNumber === 1) {
if (playQueue[currentEntryList][playQueue.player1.index]?.id) {
scrobble({
id: playQueue[currentEntryList][playQueue.player1.index]?.id,
submission: false,
});
}
} else if (playQueue[currentEntryList][playQueue.player2.index]?.id) {
scrobble({
id: playQueue[currentEntryList][playQueue.player2.index]?.id,
submission: false,
});
}
}
} }
} else if (playQueue[currentEntryList][playQueue.player2.index]?.id) {
scrobble({
id: playQueue[currentEntryList][playQueue.player2.index]?.id,
submission: false,
});
} }
} },
}; [currentEntryList, playQueue, player.currentSeek]
);
return ( return (
<> <>

Loading…
Cancel
Save