mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 21:10:12 +02:00
Fallback to web player if mpv fails to run
This commit is contained in:
@@ -149,6 +149,10 @@ export const getMpvInstance = () => {
|
||||
return mpvInstance;
|
||||
};
|
||||
|
||||
const setAudioPlayerFallback = (isError: boolean) => {
|
||||
getMainWindow()?.webContents.send('renderer-player-fallback', isError);
|
||||
};
|
||||
|
||||
ipcMain.on('player-set-properties', async (_event, data: Record<string, any>) => {
|
||||
mpvLog({ action: `Setting properties: ${JSON.stringify(data)}` });
|
||||
if (data.length === 0) {
|
||||
@@ -181,8 +185,10 @@ ipcMain.handle(
|
||||
|
||||
mpvInstance = await createMpv(data);
|
||||
mpvLog({ action: 'Restarted mpv', toast: 'success' });
|
||||
setAudioPlayerFallback(false);
|
||||
} catch (err: NodeMpvError | any) {
|
||||
mpvLog({ action: 'Failed to restart mpv' }, err);
|
||||
mpvLog({ action: 'Failed to restart mpv, falling back to web player' }, err);
|
||||
setAudioPlayerFallback(true);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -195,8 +201,10 @@ ipcMain.handle(
|
||||
action: `Attempting to initialize mpv with parameters: ${JSON.stringify(data)}`,
|
||||
});
|
||||
mpvInstance = await createMpv(data);
|
||||
setAudioPlayerFallback(false);
|
||||
} catch (err: NodeMpvError | any) {
|
||||
mpvLog({ action: 'Failed to initialize mpv' }, err);
|
||||
mpvLog({ action: 'Failed to initialize mpv, falling back to web player' }, err);
|
||||
setAudioPlayerFallback(true);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -153,6 +153,10 @@ const rendererError = (cb: (event: IpcRendererEvent, data: string) => void) => {
|
||||
ipcRenderer.on('renderer-player-error', cb);
|
||||
};
|
||||
|
||||
const rendererPlayerFallback = (cb: (event: IpcRendererEvent, data: boolean) => void) => {
|
||||
ipcRenderer.on('renderer-player-fallback', cb);
|
||||
};
|
||||
|
||||
export const mpvPlayer = {
|
||||
autoNext,
|
||||
cleanup,
|
||||
@@ -184,6 +188,7 @@ export const mpvPlayerListener = {
|
||||
rendererPause,
|
||||
rendererPlay,
|
||||
rendererPlayPause,
|
||||
rendererPlayerFallback,
|
||||
rendererPrevious,
|
||||
rendererQuit,
|
||||
rendererSkipBackward,
|
||||
|
||||
Reference in New Issue
Block a user