import type { Song } from '/@/shared/types/domain-types'; import type { CrossfadeStyle } from '/@/shared/types/types'; import type { ReactPlayerProps } from 'react-player'; import isElectron from 'is-electron'; import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'; import ReactPlayer from 'react-player/lazy'; import { api } from '/@/renderer/api'; import { crossfadeHandler, gaplessHandler, } from '/@/renderer/components/audio-player/utils/list-handlers'; import { toast } from '/@/renderer/components/toast'; import { useWebAudio } from '/@/renderer/features/player/hooks/use-webaudio'; import { getServerById, TranscodingConfig, usePlaybackSettings, useSpeed } from '/@/renderer/store'; import { useSettingsStore, useSettingsStoreActions } from '/@/renderer/store/settings.store'; import { PlaybackStyle, PlayerStatus } from '/@/shared/types/types'; export type AudioPlayerProgress = { loaded: number; loadedSeconds: number; played: number; playedSeconds: number; }; interface AudioPlayerProps extends ReactPlayerProps { autoNext: () => void; crossfadeDuration: number; crossfadeStyle: CrossfadeStyle; currentPlayer: 1 | 2; muted: boolean; playbackStyle: PlaybackStyle; player1?: Song; player2?: Song; status: PlayerStatus; volume: number; } const getDuration = (ref: any) => { return ref.current?.player?.player?.player?.duration; }; // Credits: https://gist.github.com/novwhisky/8a1a0168b94f3b6abfaa?permalink_comment_id=1551393#gistcomment-1551393 // This is used so that the player will always have an