fix mpv playback resume on queue end / stop

This commit is contained in:
jeffvli
2026-07-11 18:18:06 -07:00
parent c5d074be16
commit bafc14b55a
2 changed files with 12 additions and 1 deletions
@@ -278,7 +278,9 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
const handleTrackEnded = () => { const handleTrackEnded = () => {
const { player } = usePlayerStore.getState(); const { player } = usePlayerStore.getState();
if (player.status !== PlayerStatus.PLAYING) { // mpv often emits `stopped` before this event, which already set STOPPED
// via mediaStop. Still run mediaAutoNext so end-of-queue seek/reset runs.
if (player.status !== PlayerStatus.PLAYING && player.status !== PlayerStatus.STOPPED) {
return; return;
} }
+9
View File
@@ -1299,6 +1299,11 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
}); });
}, },
mediaTogglePlayPause: () => { mediaTogglePlayPause: () => {
// Restarting from STOPPED (e.g. end of queue) needs a full play
// event so engines like mpv can reload the current track — play()
// alone is a no-op when mpv's playlist-pos is -1.
const wasStopped = get().player.status === PlayerStatus.STOPPED;
set((state) => { set((state) => {
if (state.player.status === PlayerStatus.PLAYING) { if (state.player.status === PlayerStatus.PLAYING) {
state.player.status = PlayerStatus.PAUSED; state.player.status = PlayerStatus.PAUSED;
@@ -1306,6 +1311,10 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
state.player.status = PlayerStatus.PLAYING; state.player.status = PlayerStatus.PLAYING;
} }
}); });
if (wasStopped) {
emitPlayerPlayEvent(undefined, set, get);
}
}, },
moveSelectedTo: (items: QueueSong[], uniqueId: string, edge: 'bottom' | 'top') => { moveSelectedTo: (items: QueueSong[], uniqueId: string, edge: 'bottom' | 'top') => {
const itemUniqueIds = items.map((item) => item._uniqueId); const itemUniqueIds = items.map((item) => item._uniqueId);