mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-14 04:20:07 +02:00
provide transcoding support
This commit is contained in:
@@ -5,7 +5,6 @@ import { app, ipcMain } from 'electron';
|
||||
import uniq from 'lodash/uniq';
|
||||
import MpvAPI from 'node-mpv';
|
||||
import { getMainWindow, sendToastToRenderer } from '../../../main';
|
||||
import { PlayerData } from '/@/renderer/store';
|
||||
import { createLog, isWindows } from '../../../utils';
|
||||
import { store } from '../settings';
|
||||
|
||||
@@ -315,8 +314,8 @@ ipcMain.on('player-seek-to', async (_event, time: number) => {
|
||||
});
|
||||
|
||||
// Sets the queue in position 0 and 1 to the given data. Used when manually starting a song or using the next/prev buttons
|
||||
ipcMain.on('player-set-queue', async (_event, data: PlayerData, pause?: boolean) => {
|
||||
if (!data.queue.current?.id && !data.queue.next?.id) {
|
||||
ipcMain.on('player-set-queue', async (_event, current?: string, next?: string, pause?: boolean) => {
|
||||
if (!current && !next) {
|
||||
try {
|
||||
await getMpvInstance()?.clearPlaylist();
|
||||
await getMpvInstance()?.pause();
|
||||
@@ -327,15 +326,15 @@ ipcMain.on('player-set-queue', async (_event, data: PlayerData, pause?: boolean)
|
||||
}
|
||||
|
||||
try {
|
||||
if (data.queue.current?.streamUrl) {
|
||||
if (current) {
|
||||
try {
|
||||
await getMpvInstance()?.load(data.queue.current.streamUrl, 'replace');
|
||||
await getMpvInstance()?.load(current, 'replace');
|
||||
} catch (error) {
|
||||
await getMpvInstance()?.play();
|
||||
}
|
||||
|
||||
if (data.queue.next?.streamUrl) {
|
||||
await getMpvInstance()?.load(data.queue.next.streamUrl, 'append');
|
||||
if (next) {
|
||||
await getMpvInstance()?.load(next, 'append');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +350,7 @@ ipcMain.on('player-set-queue', async (_event, data: PlayerData, pause?: boolean)
|
||||
});
|
||||
|
||||
// Replaces the queue in position 1 to the given data
|
||||
ipcMain.on('player-set-queue-next', async (_event, data: PlayerData) => {
|
||||
ipcMain.on('player-set-queue-next', async (_event, url?: string) => {
|
||||
try {
|
||||
const size = await getMpvInstance()?.getPlaylistSize();
|
||||
|
||||
@@ -363,8 +362,8 @@ ipcMain.on('player-set-queue-next', async (_event, data: PlayerData) => {
|
||||
await getMpvInstance()?.playlistRemove(1);
|
||||
}
|
||||
|
||||
if (data.queue.next?.streamUrl) {
|
||||
await getMpvInstance()?.load(data.queue.next.streamUrl, 'append');
|
||||
if (url) {
|
||||
await getMpvInstance()?.load(url, 'append');
|
||||
}
|
||||
} catch (err: NodeMpvError | any) {
|
||||
mpvLog({ action: `Failed to set play queue` }, err);
|
||||
@@ -372,7 +371,7 @@ ipcMain.on('player-set-queue-next', async (_event, data: PlayerData) => {
|
||||
});
|
||||
|
||||
// Sets the next song in the queue when reaching the end of the queue
|
||||
ipcMain.on('player-auto-next', async (_event, data: PlayerData) => {
|
||||
ipcMain.on('player-auto-next', async (_event, url?: string) => {
|
||||
// Always keep the current song as position 0 in the mpv queue
|
||||
// This allows us to easily set update the next song in the queue without
|
||||
// disturbing the currently playing song
|
||||
@@ -383,8 +382,8 @@ ipcMain.on('player-auto-next', async (_event, data: PlayerData) => {
|
||||
getMpvInstance()?.pause();
|
||||
});
|
||||
|
||||
if (data.queue.next?.streamUrl) {
|
||||
await getMpvInstance()?.load(data.queue.next.streamUrl, 'append');
|
||||
if (url) {
|
||||
await getMpvInstance()?.load(url, 'append');
|
||||
}
|
||||
} catch (err: NodeMpvError | any) {
|
||||
mpvLog({ action: `Failed to load next song` }, err);
|
||||
|
||||
Reference in New Issue
Block a user