Clean up mpv startup

This commit is contained in:
jeffvli 2023-05-20 19:56:17 -07:00
parent 35f9798bed
commit 6a01d44600
3 changed files with 34 additions and 18 deletions

View file

@ -342,15 +342,20 @@ const createMpv = (data: { extraParameters?: string[]; properties?: Record<strin
params,
);
console.log('Setting mpv properties: ', properties);
console.log('Setting MPV properties: ', properties);
mpvInstance.setMultipleProperties(properties || {});
mpvInstance.start().catch((error) => {
console.log('error starting mpv', error);
console.log('MPV Event: start error', error);
});
mpvInstance.on('status', (status) => {
mpvInstance.on('status', (status, ...rest) => {
console.log('MPV Event: status', status.property, status.value, rest);
if (status.property === 'playlist-pos') {
if (status.value === -1) {
mpvInstance?.stop();
}
if (status.value !== 0) {
getMainWindow()?.webContents.send('renderer-player-auto-next');
}
@ -359,16 +364,19 @@ const createMpv = (data: { extraParameters?: string[]; properties?: Record<strin
// Automatically updates the play button when the player is playing
mpvInstance.on('resumed', () => {
console.log('MPV Event: resumed');
getMainWindow()?.webContents.send('renderer-player-play');
});
// Automatically updates the play button when the player is stopped
mpvInstance.on('stopped', () => {
console.log('MPV Event: stopped');
getMainWindow()?.webContents.send('renderer-player-stop');
});
// Automatically updates the play button when the player is paused
mpvInstance.on('paused', () => {
console.log('MPV Event: paused');
getMainWindow()?.webContents.send('renderer-player-pause');
});
@ -376,6 +384,10 @@ const createMpv = (data: { extraParameters?: string[]; properties?: Record<strin
mpvInstance.on('timeposition', (time: number) => {
getMainWindow()?.webContents.send('renderer-player-current-time', time);
});
mpvInstance.on('quit', () => {
console.log('MPV Event: quit');
});
};
export const getMpvInstance = () => {