mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
add web visualizer (#314)
* add web visualizer * fallback to simple model * less samples, hopefully more efficient * Use audiomotion analyzer - Note: fixed to 4.1.1 because 4.2.0 uses esm which breaks in the current workflow... * revert publish changes * r2 * don't massively change package.json * lazy
This commit is contained in:
parent
fbac33ceba
commit
74aa88e082
9 changed files with 172 additions and 33 deletions
|
|
@ -18,6 +18,7 @@ import {
|
|||
import { useSettingsStore, useSettingsStoreActions } from '/@/renderer/store/settings.store';
|
||||
import type { CrossfadeStyle } from '/@/renderer/types';
|
||||
import { PlaybackStyle, PlayerStatus } from '/@/renderer/types';
|
||||
import { useWebAudio } from '/@/renderer/features/player/hooks/use-webaudio';
|
||||
import { getServerById, TranscodingConfig, usePlaybackSettings, useSpeed } from '/@/renderer/store';
|
||||
import { toast } from '/@/renderer/components/toast';
|
||||
import { api } from '/@/renderer/api';
|
||||
|
|
@ -44,11 +45,6 @@ const getDuration = (ref: any) => {
|
|||
return ref.current?.player?.player?.player?.duration;
|
||||
};
|
||||
|
||||
type WebAudio = {
|
||||
context: AudioContext;
|
||||
gain: GainNode;
|
||||
};
|
||||
|
||||
// Credits: https://gist.github.com/novwhisky/8a1a0168b94f3b6abfaa?permalink_comment_id=1551393#gistcomment-1551393
|
||||
// This is used so that the player will always have an <audio> element. This means that
|
||||
// player1Source and player2Source are connected BEFORE the user presses play for
|
||||
|
|
@ -116,7 +112,7 @@ export const AudioPlayer = forwardRef(
|
|||
const [isTransitioning, setIsTransitioning] = useState(false);
|
||||
const audioDeviceId = useSettingsStore((state) => state.playback.audioDeviceId);
|
||||
const playback = useSettingsStore((state) => state.playback.mpvProperties);
|
||||
const useWebAudio = useSettingsStore((state) => state.playback.webAudio);
|
||||
const shouldUseWebAudio = useSettingsStore((state) => state.playback.webAudio);
|
||||
const { resetSampleRate } = useSettingsStoreActions();
|
||||
const playbackSpeed = useSpeed();
|
||||
const { transcode } = usePlaybackSettings();
|
||||
|
|
@ -124,7 +120,7 @@ export const AudioPlayer = forwardRef(
|
|||
const stream1 = useSongUrl(transcode, currentPlayer === 1, player1);
|
||||
const stream2 = useSongUrl(transcode, currentPlayer === 2, player2);
|
||||
|
||||
const [webAudio, setWebAudio] = useState<WebAudio | null>(null);
|
||||
const { webAudio, setWebAudio } = useWebAudio();
|
||||
const [player1Source, setPlayer1Source] = useState<MediaElementAudioSourceNode | null>(
|
||||
null,
|
||||
);
|
||||
|
|
@ -181,7 +177,7 @@ export const AudioPlayer = forwardRef(
|
|||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (useWebAudio && 'AudioContext' in window) {
|
||||
if (shouldUseWebAudio && 'AudioContext' in window) {
|
||||
let context: AudioContext;
|
||||
|
||||
try {
|
||||
|
|
@ -200,7 +196,7 @@ export const AudioPlayer = forwardRef(
|
|||
const gain = context.createGain();
|
||||
gain.connect(context.destination);
|
||||
|
||||
setWebAudio({ context, gain });
|
||||
setWebAudio!({ context, gain });
|
||||
|
||||
return () => {
|
||||
return context.close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue