import { useEffect, useState } from 'react'; import { SelectItem } from '@mantine/core'; import isElectron from 'is-electron'; import { Select, Slider, toast } from '/@/renderer/components'; import { SettingsSection, SettingOption, } from '/@/renderer/features/settings/components/settings-section'; import { useCurrentStatus, usePlayerStore } from '/@/renderer/store'; import { usePlaybackSettings, useSettingsStoreActions } from '/@/renderer/store/settings.store'; import { PlaybackType, PlayerStatus, PlaybackStyle, CrossfadeStyle } from '/@/renderer/types'; const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null; const getAudioDevice = async () => { const devices = await navigator.mediaDevices.enumerateDevices(); return (devices || []).filter((dev: MediaDeviceInfo) => dev.kind === 'audiooutput'); }; export const AudioSettings = () => { const settings = usePlaybackSettings(); const { setSettings } = useSettingsStoreActions(); const status = useCurrentStatus(); const [audioDevices, setAudioDevices] = useState([]); useEffect(() => { const getAudioDevices = () => { getAudioDevice() .then((dev) => setAudioDevices(dev.map((d) => ({ label: d.label, value: d.deviceId }))), ) .catch(() => toast.error({ message: 'Error fetching audio devices' })); }; if (settings.type === PlaybackType.WEB) { getAudioDevices(); } }, [settings.type]); const audioOptions: SettingOption[] = [ { control: ( setSettings({ playback: { ...settings, audioDeviceId: e } })} /> ), description: 'The audio device to use for playback (web player only)', isHidden: !isElectron() || settings.type !== PlaybackType.WEB, title: 'Audio device', }, { control: ( { if (!e) return; setSettings({ playback: { ...settings, crossfadeStyle: e as CrossfadeStyle }, }); }} /> ), description: 'Change the crossfade algorithm (web player only)', isHidden: settings.type !== PlaybackType.WEB, note: status === PlayerStatus.PLAYING ? 'Player must be paused' : undefined, title: 'Crossfade Style', }, ]; return ; };