mirror of
https://github.com/jeffvli/feishin.git
synced 2024-11-20 14:37:06 +01:00
Fix mpv stopping after first playback
- On startup, the first time a song is played, mpv will stop after playback - This adds a loop to the queue handler to automatically retry when failing to add to the queue
This commit is contained in:
parent
7f9de4b180
commit
275d68ec5b
@ -4,6 +4,19 @@ import { PlayerData } from '/@/renderer/store';
|
||||
|
||||
declare module 'node-mpv';
|
||||
|
||||
function wait(timeout: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve('resolved');
|
||||
}, timeout);
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.on('player-start', async () => {
|
||||
await mpv.load('./dummy.mp3', 'replace');
|
||||
await mpv.play();
|
||||
});
|
||||
|
||||
// Starts the player
|
||||
ipcMain.on('player-play', async () => {
|
||||
await mpv.play();
|
||||
@ -47,15 +60,25 @@ ipcMain.on('player-set-queue', async (_event, data: PlayerData) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.queue.current) {
|
||||
await mpv.load(data.queue.current.streamUrl, 'replace');
|
||||
}
|
||||
let complete = false;
|
||||
|
||||
if (data.queue.next) {
|
||||
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||
}
|
||||
while (!complete) {
|
||||
try {
|
||||
if (data.queue.current) {
|
||||
await mpv.load(data.queue.current.streamUrl, 'replace');
|
||||
}
|
||||
|
||||
await mpv.play();
|
||||
if (data.queue.next) {
|
||||
await mpv.load(data.queue.next.streamUrl, 'append');
|
||||
}
|
||||
|
||||
await mpv.play();
|
||||
complete = true;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await wait(500);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Replaces the queue in position 1 to the given data
|
||||
|
@ -168,6 +168,20 @@ export const useHandlePlayQueueAdd = () => {
|
||||
if (!songs) return toast.warn({ message: 'No songs found' });
|
||||
|
||||
const playerData = usePlayerStore.getState().actions.addToQueue(songs, options.play);
|
||||
|
||||
if (playerType === PlaybackType.LOCAL) {
|
||||
if (options.play === Play.NEXT || options.play === Play.LAST) {
|
||||
mpvPlayer.setQueueNext(playerData);
|
||||
}
|
||||
|
||||
if (options.play === Play.NOW) {
|
||||
mpvPlayer.setQueue(playerData);
|
||||
mpvPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
play();
|
||||
|
||||
mpris?.updateSong({
|
||||
currentTime: usePlayerStore.getState().current.time,
|
||||
repeat: usePlayerStore.getState().repeat,
|
||||
@ -176,21 +190,6 @@ export const useHandlePlayQueueAdd = () => {
|
||||
status: 'Playing',
|
||||
});
|
||||
|
||||
if (options.play === Play.NEXT || options.play === Play.LAST) {
|
||||
if (playerType === PlaybackType.LOCAL) {
|
||||
mpvPlayer.setQueueNext(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.play === Play.NOW) {
|
||||
if (playerType === PlaybackType.LOCAL) {
|
||||
mpvPlayer.setQueue(playerData);
|
||||
mpvPlayer.play();
|
||||
}
|
||||
|
||||
play();
|
||||
}
|
||||
|
||||
// if (fetchId) {
|
||||
// toast.update({
|
||||
// autoClose: 1000,
|
||||
|
Loading…
Reference in New Issue
Block a user