Browse Source

player fixes

master
jeffvli 3 years ago
parent
commit
bcf43754ee
  1. 11
      src/components/player/Player.tsx
  2. 8
      src/redux/playQueueSlice.ts

11
src/components/player/Player.tsx

@ -308,7 +308,7 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
the currentSongIndex such as when sorting the table, shuffling, or drag and dropping rows. the currentSongIndex such as when sorting the table, shuffling, or drag and dropping rows.
It can also prevent loading unneeded tracks when rapidly incrementing/decrementing the player. */ It can also prevent loading unneeded tracks when rapidly incrementing/decrementing the player. */
if (playQueue[currentEntryList] && !playQueue.isFading) { if (playQueue[currentEntryList].length > 0 && !playQueue.isFading) {
const timer1 = setTimeout(() => { const timer1 = setTimeout(() => {
dispatch(setPlayerSrc({ player: 1, src: getSrc1() })); dispatch(setPlayerSrc({ player: 1, src: getSrc1() }));
}, 100); }, 100);
@ -323,10 +323,13 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
}; };
} }
if (playQueue[currentEntryList].length > 0) {
/* If fading, just instantly switch the track, otherwise the player breaks /* If fading, just instantly switch the track, otherwise the player breaks
from the timeout due to the listen handlers that run during the fade */ from the timeout due to the listen handlers that run during the fade */
dispatch(setPlayerSrc({ player: 1, src: getSrc1() })); dispatch(setPlayerSrc({ player: 1, src: getSrc1() }));
dispatch(setPlayerSrc({ player: 2, src: getSrc2() })); dispatch(setPlayerSrc({ player: 2, src: getSrc2() }));
}
return undefined; return undefined;
}, [cachePath, currentEntryList, dispatch, getSrc1, getSrc2, playQueue]); }, [cachePath, currentEntryList, dispatch, getSrc1, getSrc2, playQueue]);
@ -505,10 +508,13 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
playQueue.currentPlayer === 1 playQueue.currentPlayer === 1
} }
onError={(e: any) => { onError={(e: any) => {
if (playQueue[currentEntryList].length > 0) {
console.log('player error', e); console.log('player error', e);
player1Ref.current.audioEl.current.src = player1Ref.current.audioEl.current.src =
'./components/player/dummy.mp3'; './components/player/dummy.mp3';
player1Ref.current.audioEl.current.src = getSrc1(); player1Ref.current.audioEl.current.src = getSrc1();
}
}} }}
crossOrigin="anonymous" crossOrigin="anonymous"
/> />
@ -527,10 +533,13 @@ const Player = ({ currentEntryList, children }: any, ref: any) => {
playQueue.currentPlayer === 2 playQueue.currentPlayer === 2
} }
onError={(e: any) => { onError={(e: any) => {
if (playQueue[currentEntryList].length > 0) {
console.log('player error', e); console.log('player error', e);
player2Ref.current.audioEl.current.src = player2Ref.current.audioEl.current.src =
'./components/player/dummy.mp3'; './components/player/dummy.mp3';
player2Ref.current.audioEl.current.src = getSrc2(); player2Ref.current.audioEl.current.src = getSrc2();
}
}} }}
crossOrigin="anonymous" crossOrigin="anonymous"
/> />

8
src/redux/playQueueSlice.ts

@ -83,7 +83,7 @@ export interface PlayQueue {
const initialState: PlayQueue = { const initialState: PlayQueue = {
player1: { player1: {
src: '', src: './components/player/dummy.mp3',
index: 0, index: 0,
volume: 0.5, volume: 0.5,
fadeData: { fadeData: {
@ -92,7 +92,7 @@ const initialState: PlayQueue = {
}, },
}, },
player2: { player2: {
src: '', src: './components/player/dummy.mp3',
index: 1, index: 1,
volume: 0, volume: 0,
fadeData: { fadeData: {
@ -129,6 +129,8 @@ const resetPlayerDefaults = (state: PlayQueue) => {
state.currentIndex = 0; state.currentIndex = 0;
state.currentSongId = ''; state.currentSongId = '';
state.currentPlayer = 1; state.currentPlayer = 1;
state.player1.src = './components/player/dummy.mp3';
state.player2.src = './components/player/dummy.mp3';
state.player1.index = 0; state.player1.index = 0;
state.player1.volume = state.volume; state.player1.volume = state.volume;
state.player2.index = 0; state.player2.index = 0;
@ -657,7 +659,7 @@ const playQueueSlice = createSlice({
Player2 will continue playing even after decrementing. This reducer resets the Player2 index and Player2 will continue playing even after decrementing. This reducer resets the Player2 index and
then sets it to its proper index. */ then sets it to its proper index. */
state.player2.src = ''; state.player2.src = './components/player/dummy.mp3';
state.player2.index = getNextPlayerIndex( state.player2.index = getNextPlayerIndex(
state.entry.length, state.entry.length,

Loading…
Cancel
Save