mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-24 12:57:55 +02:00
fix missing emitters from onPlayerPlay
This commit is contained in:
@@ -53,16 +53,11 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
|||||||
const isInitializedRef = useRef<boolean>(false);
|
const isInitializedRef = useRef<boolean>(false);
|
||||||
const hasPopulatedQueueRef = useRef<boolean>(false);
|
const hasPopulatedQueueRef = useRef<boolean>(false);
|
||||||
const isMountedRef = useRef<boolean>(true);
|
const isMountedRef = useRef<boolean>(true);
|
||||||
// const currentSrcRef = useRef<string | undefined>(currentSrc);
|
|
||||||
// const nextSrcRef = useRef<string | undefined>(nextSrc);
|
|
||||||
|
|
||||||
const { transcode } = usePlaybackSettings();
|
const { transcode } = usePlaybackSettings();
|
||||||
const mpvExtraParameters = useSettingsStore((store) => store.playback.mpvExtraParameters);
|
const mpvExtraParameters = useSettingsStore((store) => store.playback.mpvExtraParameters);
|
||||||
const mpvProperties = useSettingsStore((store) => store.playback.mpvProperties);
|
const mpvProperties = useSettingsStore((store) => store.playback.mpvProperties);
|
||||||
|
|
||||||
// const [previousCurrentSrc, setPreviousCurrentSrc] = useState<string | undefined>(currentSrc);
|
|
||||||
// const [previousNextSrc, setPreviousNextSrc] = useState<string | undefined>(nextSrc);
|
|
||||||
|
|
||||||
// Start the mpv instance on startup
|
// Start the mpv instance on startup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isMountedRef.current = true;
|
isMountedRef.current = true;
|
||||||
|
|||||||
@@ -501,6 +501,21 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const currentState = get();
|
||||||
|
const queue = currentState.getQueue();
|
||||||
|
const currentIndex = currentState.player.index;
|
||||||
|
const currentSong = queue.items[currentIndex];
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentSong &&
|
||||||
|
currentIndex !== undefined &&
|
||||||
|
currentIndex >= 0
|
||||||
|
) {
|
||||||
|
eventEmitter.emit('PLAYER_PLAY', {
|
||||||
|
id: currentSong._uniqueId,
|
||||||
|
index: currentIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Play.SHUFFLE: {
|
case Play.SHUFFLE: {
|
||||||
@@ -527,6 +542,22 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Emit PLAYER_PLAY event after state is updated
|
||||||
|
const currentState = get();
|
||||||
|
const queue = currentState.getQueue();
|
||||||
|
const currentIndex = currentState.player.index;
|
||||||
|
const currentSong = queue.items[currentIndex];
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentSong &&
|
||||||
|
currentIndex !== undefined &&
|
||||||
|
currentIndex >= 0
|
||||||
|
) {
|
||||||
|
eventEmitter.emit('PLAYER_PLAY', {
|
||||||
|
id: currentSong._uniqueId,
|
||||||
|
index: currentIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -769,6 +800,22 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
generateShuffledIndexes(combinedLength);
|
generateShuffledIndexes(combinedLength);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const currentState = get();
|
||||||
|
const queue = currentState.getQueue();
|
||||||
|
const currentIndex = currentState.player.index;
|
||||||
|
const currentSong = queue.items[currentIndex];
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentSong &&
|
||||||
|
currentIndex !== undefined &&
|
||||||
|
currentIndex >= 0
|
||||||
|
) {
|
||||||
|
eventEmitter.emit('PLAYER_PLAY', {
|
||||||
|
id: currentSong._uniqueId,
|
||||||
|
index: currentIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Play.SHUFFLE: {
|
case Play.SHUFFLE: {
|
||||||
@@ -797,6 +844,18 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
shuffledIds.length,
|
shuffledIds.length,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Emit PLAYER_PLAY event after state is updated
|
||||||
|
const currentState = get();
|
||||||
|
const queue = currentState.getQueue();
|
||||||
|
const currentIndex = currentState.player.index;
|
||||||
|
const currentSong = queue.items[currentIndex];
|
||||||
|
if (currentSong && currentIndex !== undefined) {
|
||||||
|
eventEmitter.emit('PLAYER_PLAY', {
|
||||||
|
id: currentSong._uniqueId,
|
||||||
|
index: currentIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -806,6 +865,7 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
|
|
||||||
// If playSongId is provided, find the song and start playback on it
|
// If playSongId is provided, find the song and start playback on it
|
||||||
if (targetSongUniqueId) {
|
if (targetSongUniqueId) {
|
||||||
|
let playIndex: number | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const queue = state.getQueue();
|
const queue = state.getQueue();
|
||||||
const queueIndex = queue.items.findIndex(
|
const queueIndex = queue.items.findIndex(
|
||||||
@@ -823,16 +883,27 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
);
|
);
|
||||||
if (shuffledPosition !== -1) {
|
if (shuffledPosition !== -1) {
|
||||||
state.player.index = shuffledPosition;
|
state.player.index = shuffledPosition;
|
||||||
|
playIndex = shuffledPosition;
|
||||||
} else {
|
} else {
|
||||||
state.player.index = queueIndex;
|
state.player.index = queueIndex;
|
||||||
|
playIndex = queueIndex;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.player.index = queueIndex;
|
state.player.index = queueIndex;
|
||||||
|
playIndex = queueIndex;
|
||||||
}
|
}
|
||||||
state.player.status = PlayerStatus.PLAYING;
|
state.player.status = PlayerStatus.PLAYING;
|
||||||
setTimestampStore(0);
|
setTimestampStore(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Emit PLAYER_PLAY event if playback was started
|
||||||
|
if (playIndex !== undefined) {
|
||||||
|
eventEmitter.emit('PLAYER_PLAY', {
|
||||||
|
id: targetSongUniqueId,
|
||||||
|
index: playIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
addToQueueByUniqueId: (items, uniqueId, edge, playSongId) => {
|
addToQueueByUniqueId: (items, uniqueId, edge, playSongId) => {
|
||||||
@@ -1029,6 +1100,7 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
|
|
||||||
// If playSongId is provided, find the song and start playback on it
|
// If playSongId is provided, find the song and start playback on it
|
||||||
if (targetSongUniqueId) {
|
if (targetSongUniqueId) {
|
||||||
|
let playIndex: number | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const queue = state.getQueue();
|
const queue = state.getQueue();
|
||||||
const queueIndex = queue.items.findIndex(
|
const queueIndex = queue.items.findIndex(
|
||||||
@@ -1046,16 +1118,27 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
);
|
);
|
||||||
if (shuffledPosition !== -1) {
|
if (shuffledPosition !== -1) {
|
||||||
state.player.index = shuffledPosition;
|
state.player.index = shuffledPosition;
|
||||||
|
playIndex = shuffledPosition;
|
||||||
} else {
|
} else {
|
||||||
state.player.index = queueIndex;
|
state.player.index = queueIndex;
|
||||||
|
playIndex = queueIndex;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.player.index = queueIndex;
|
state.player.index = queueIndex;
|
||||||
|
playIndex = queueIndex;
|
||||||
}
|
}
|
||||||
state.player.status = PlayerStatus.PLAYING;
|
state.player.status = PlayerStatus.PLAYING;
|
||||||
setTimestampStore(0);
|
setTimestampStore(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Emit PLAYER_PLAY event if playback was started
|
||||||
|
if (playIndex !== undefined) {
|
||||||
|
eventEmitter.emit('PLAYER_PLAY', {
|
||||||
|
id: targetSongUniqueId,
|
||||||
|
index: playIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clearQueue: () => {
|
clearQueue: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user