Improve MPV initialization and restore (#222)
- set mpv settings only after it has successfully started (at least on linux, settings were not taken) - change timing of restore queue to behave properly
This commit is contained in:
parent
b60ba27892
commit
1acfa93f1a
3 changed files with 16 additions and 13 deletions
|
|
@ -11,11 +11,6 @@
|
||||||
import { access, constants, readFile, writeFile } from 'fs';
|
import { access, constants, readFile, writeFile } from 'fs';
|
||||||
import path, { join } from 'path';
|
import path, { join } from 'path';
|
||||||
import { deflate, inflate } from 'zlib';
|
import { deflate, inflate } from 'zlib';
|
||||||
import electronLocalShortcut from 'electron-localshortcut';
|
|
||||||
import log from 'electron-log';
|
|
||||||
import { autoUpdater } from 'electron-updater';
|
|
||||||
import uniq from 'lodash/uniq';
|
|
||||||
import MpvAPI from 'node-mpv';
|
|
||||||
import {
|
import {
|
||||||
app,
|
app,
|
||||||
BrowserWindow,
|
BrowserWindow,
|
||||||
|
|
@ -27,6 +22,11 @@ import {
|
||||||
nativeImage,
|
nativeImage,
|
||||||
BrowserWindowConstructorOptions,
|
BrowserWindowConstructorOptions,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
|
import electronLocalShortcut from 'electron-localshortcut';
|
||||||
|
import log from 'electron-log';
|
||||||
|
import { autoUpdater } from 'electron-updater';
|
||||||
|
import uniq from 'lodash/uniq';
|
||||||
|
import MpvAPI from 'node-mpv';
|
||||||
import { disableMediaKeys, enableMediaKeys } from './features/core/player/media-keys';
|
import { disableMediaKeys, enableMediaKeys } from './features/core/player/media-keys';
|
||||||
import { store } from './features/core/settings/index';
|
import { store } from './features/core/settings/index';
|
||||||
import MenuBuilder from './menu';
|
import MenuBuilder from './menu';
|
||||||
|
|
@ -453,12 +453,15 @@ const createMpv = (data: { extraParameters?: string[]; properties?: Record<strin
|
||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('Setting MPV properties: ', properties);
|
// eslint-disable-next-line promise/catch-or-return
|
||||||
mpv.setMultipleProperties(properties || {});
|
mpv.start()
|
||||||
|
.catch((error) => {
|
||||||
mpv.start().catch((error) => {
|
console.log('MPV failed to start', error);
|
||||||
console.log('MPV failed to start', error);
|
})
|
||||||
});
|
.finally(() => {
|
||||||
|
console.log('Setting MPV properties: ', properties);
|
||||||
|
mpv.setMultipleProperties(properties || {});
|
||||||
|
});
|
||||||
|
|
||||||
mpv.on('status', (status, ...rest) => {
|
mpv.on('status', (status, ...rest) => {
|
||||||
console.log('MPV Event: status', status.property, status.value, rest);
|
console.log('MPV Event: status', status.property, status.value, rest);
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ export const App = () => {
|
||||||
|
|
||||||
mpvPlayer?.volume(properties.volume);
|
mpvPlayer?.volume(properties.volume);
|
||||||
}
|
}
|
||||||
|
mpvPlayer?.restoreQueue();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isElectron() && playbackType === PlaybackType.LOCAL) {
|
if (isElectron() && playbackType === PlaybackType.LOCAL) {
|
||||||
|
|
@ -94,8 +95,6 @@ export const App = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
mpvPlayer!.restoreQueue();
|
|
||||||
|
|
||||||
mpvPlayerListener!.rendererSaveQueue(() => {
|
mpvPlayerListener!.rendererSaveQueue(() => {
|
||||||
const { current, queue } = usePlayerStore.getState();
|
const { current, queue } = usePlayerStore.getState();
|
||||||
const stateToSave: Partial<Pick<PlayerState, 'current' | 'queue'>> = {
|
const stateToSave: Partial<Pick<PlayerState, 'current' | 'queue'>> = {
|
||||||
|
|
|
||||||
|
|
@ -701,6 +701,7 @@ export const usePlayerStore = create<PlayerSlice>()(
|
||||||
state.current = {
|
state.current = {
|
||||||
...state.current,
|
...state.current,
|
||||||
...data.current,
|
...data.current,
|
||||||
|
time: 0,
|
||||||
};
|
};
|
||||||
state.queue = {
|
state.queue = {
|
||||||
...state.queue,
|
...state.queue,
|
||||||
|
|
|
||||||
Reference in a new issue