Update player/shared components

This commit is contained in:
jeffvli
2022-10-24 22:30:16 -07:00
parent 8973571147
commit dd3de66232
21 changed files with 164 additions and 139 deletions
@@ -42,7 +42,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
};
const handlePlay = useCallback(() => {
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
mpvPlayer.play();
} else {
currentPlayerRef.getInternalPlayer().play();
@@ -52,7 +52,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
}, [currentPlayerRef, play, settings]);
const handlePause = useCallback(() => {
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
mpvPlayer.pause();
}
@@ -60,7 +60,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
}, [pause, settings]);
const handleStop = () => {
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
mpvPlayer.stop();
} else {
stopPlayback();
@@ -73,7 +73,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
const handleNextTrack = useCallback(() => {
const playerData = next();
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
mpvPlayer.setQueue(playerData);
mpvPlayer.next();
} else {
@@ -86,7 +86,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
const handlePrevTrack = useCallback(() => {
const playerData = prev();
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
mpvPlayer.setQueue(playerData);
mpvPlayer.previous();
} else {
@@ -98,7 +98,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
const handlePlayPause = useCallback(() => {
if (queue) {
if (playerStatus === PlayerStatus.Paused) {
if (playerStatus === PlayerStatus.PAUSED) {
return handlePlay();
}
@@ -111,7 +111,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
const handleSkipBackward = () => {
const skipBackwardSec = 5;
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
const newTime = currentTime - skipBackwardSec;
mpvPlayer.seek(-skipBackwardSec);
setCurrentTime(newTime < 0 ? 0 : newTime);
@@ -126,7 +126,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
const handleSkipForward = () => {
const skipForwardSec = 5;
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
const newTime = currentTime + skipForwardSec;
mpvPlayer.seek(skipForwardSec);
setCurrentTime(newTime);
@@ -147,7 +147,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
(e: number | any) => {
setCurrentTime(e);
if (settings.type === PlaybackType.Local) {
if (settings.type === PlaybackType.LOCAL) {
mpvPlayer.seekTo(e);
} else {
currentPlayerRef.seekTo(e);
@@ -1,23 +1,19 @@
import { api } from '@/renderer/api';
import { Item, Play } from '../../../../types';
import { albumsApi } from '../../../api/albumsApi';
import { usePlayerStore } from '../../../store';
import {
getJellyfinStreamUrl,
getServerFolderAuth,
getSubsonicStreamUrl,
} from '../../../utils';
import { useAuthStore, usePlayerStore } from '../../../store';
import { mpvPlayer } from '../utils/mpvPlayer';
const getEndpointByItemType = (item: Item) => {
switch (item) {
case Item.ALBUM:
return albumsApi.getAlbum;
return api.albums.getAlbumDetail;
default:
return albumsApi.getAlbum;
return api.albums.getAlbumDetail;
}
};
export const usePlayQueueHandler = () => {
const serverId = useAuthStore((state) => state.currentServer?.id) || '';
const addToQueue = usePlayerStore((state) => state.addToQueue);
const handlePlayQueueAdd = async (options: {
@@ -35,36 +31,42 @@ export const usePlayQueueHandler = () => {
if (options.byItemType) {
const deviceId = localStorage.getItem('device_id');
const { serverUrl } = JSON.parse(
localStorage.getItem('authentication') || '{}'
);
// const { state } = JSON.parse(
// localStorage.getItem('authentication') || '{}'
// );
if (deviceId) {
const endpoint = getEndpointByItemType(options.byItemType.type);
const { data } = await endpoint({
id: options.byItemType.id,
albumId: options.byItemType.id,
serverId,
});
const songs = data.songs.map((song) => {
const auth = getServerFolderAuth(serverUrl, song.serverFolderId);
const songs = data.songs?.map((song) => {
// const auth = getServerFolderAuth(
// state.serverUrl,
// song.serverFolderId
// );
if (auth) {
const streamUrl =
auth.type === 'jellyfin'
? getJellyfinStreamUrl(auth, song, deviceId)
: getSubsonicStreamUrl(auth, song, deviceId);
// if (auth) {
// const streamUrl =
// auth.type === 'jellyfin'
// ? getJellyfinStreamUrl(auth, song, deviceId)
// : getSubsonicStreamUrl(auth, song, deviceId);
return {
...song,
streamUrl,
};
}
// return {
// ...song,
// streamUrl,
// };
// }
return song;
});
const playerData = addToQueue(songs, options.play);
const playerData = addToQueue(songs || [], options.play);
console.log('playerData', playerData);
if (options.play === Play.NEXT || options.play === Play.LAST) {
mpvPlayer.setQueueNext(playerData);