fix mpv autoNext and next song replacement behavior

This commit is contained in:
jeffvli
2025-12-12 18:25:06 -08:00
parent 1bcc23862c
commit 29a5fa3f74
3 changed files with 97 additions and 30 deletions
@@ -3,6 +3,7 @@ import { useEffect } from 'react';
import { eventEmitter } from '/@/renderer/events/event-emitter';
import {
subscribeCurrentTrack,
subscribeNextSongInsertion,
subscribePlayerMute,
subscribePlayerProgress,
subscribePlayerQueue,
@@ -27,6 +28,7 @@ interface PlayerEventsCallbacks {
) => void;
onMediaNext?: (properties: { currentIndex: number; nextIndex: number }) => void;
onMediaPrev?: (properties: { currentIndex: number; prevIndex: number }) => void;
onNextSongInsertion?: (song: QueueSong | undefined) => void;
onPlayerMute?: (properties: { muted: boolean }, prev: { muted: boolean }) => void;
onPlayerPlay?: (properties: { id: string; index: number }) => void;
onPlayerProgress?: (properties: { timestamp: number }, prev: { timestamp: number }) => void;
@@ -78,6 +80,12 @@ function createPlayerEvents(callbacks: PlayerEventsCallbacks): PlayerEvents {
unsubscribers.push(unsubscribe);
}
// Subscribe to next song insertions (when a song is added at next position)
if (callbacks.onNextSongInsertion) {
const unsubscribe = subscribeNextSongInsertion(callbacks.onNextSongInsertion);
unsubscribers.push(unsubscribe);
}
// Subscribe to player progress
if (callbacks.onPlayerProgress) {
const unsubscribe = subscribePlayerProgress(callbacks.onPlayerProgress);