mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
Add configurable web audio device
This commit is contained in:
@@ -4,13 +4,16 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useEffect,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
import isElectron from 'is-electron';
|
||||||
import ReactPlayer, { ReactPlayerProps } from 'react-player';
|
import ReactPlayer, { ReactPlayerProps } from 'react-player';
|
||||||
import { Song } from '@/renderer/api/types';
|
import { Song } from '@/renderer/api/types';
|
||||||
import {
|
import {
|
||||||
crossfadeHandler,
|
crossfadeHandler,
|
||||||
gaplessHandler,
|
gaplessHandler,
|
||||||
} from '@/renderer/components/audio-player/utils/list-handlers';
|
} from '@/renderer/components/audio-player/utils/list-handlers';
|
||||||
|
import { useSettingsStore } from '@/renderer/store/settings.store';
|
||||||
import { CrossfadeStyle, PlaybackStyle, PlayerStatus } from '@/renderer/types';
|
import { CrossfadeStyle, PlaybackStyle, PlayerStatus } from '@/renderer/types';
|
||||||
|
|
||||||
interface AudioPlayerProps extends ReactPlayerProps {
|
interface AudioPlayerProps extends ReactPlayerProps {
|
||||||
@@ -54,6 +57,9 @@ export const AudioPlayer = forwardRef(
|
|||||||
const player1Ref = useRef<any>(null);
|
const player1Ref = useRef<any>(null);
|
||||||
const player2Ref = useRef<any>(null);
|
const player2Ref = useRef<any>(null);
|
||||||
const [isTransitioning, setIsTransitioning] = useState(false);
|
const [isTransitioning, setIsTransitioning] = useState(false);
|
||||||
|
const audioDeviceId = useSettingsStore(
|
||||||
|
(state) => state.player.audioDeviceId
|
||||||
|
);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
get player1() {
|
get player1() {
|
||||||
@@ -147,6 +153,18 @@ export const AudioPlayer = forwardRef(
|
|||||||
[isTransitioning, player2?.container]
|
[isTransitioning, player2?.container]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isElectron()) {
|
||||||
|
if (audioDeviceId) {
|
||||||
|
player1Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId);
|
||||||
|
player2Ref.current?.getInternalPlayer()?.setSinkId(audioDeviceId);
|
||||||
|
} else {
|
||||||
|
player1Ref.current?.getInternalPlayer()?.setSinkId('');
|
||||||
|
player2Ref.current?.getInternalPlayer()?.setSinkId('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [audioDeviceId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ReactPlayer
|
<ReactPlayer
|
||||||
|
|||||||
Reference in New Issue
Block a user