@@ -87,40 +87,28 @@ export const useSoundPlayer = (props: {
8787 }
8888 } , [ ] ) ;
8989
90- const addToQueue = useCallback (
91- async ( message : AudioOutputMessage ) => {
92- if ( ! isInitialized . current || ! audioContext . current ) {
93- onError . current ( 'Audio player has not been initialized' ) ;
94- return ;
95- }
90+ const addToQueue = useCallback ( async ( message : AudioOutputMessage ) => {
91+ if ( ! isInitialized . current || ! audioContext . current ) {
92+ onError . current ( 'Audio player has not been initialized' ) ;
93+ return ;
94+ }
9695
97- try {
98- const blob = convertBase64ToBlob ( message . data ) ;
99- const arrayBuffer = await blob . arrayBuffer ( ) ;
100- const audioBuffer =
101- await audioContext . current . decodeAudioData ( arrayBuffer ) ;
102-
103- const pcmData = audioBuffer . getChannelData ( 0 ) ;
104- workletNode . current ?. port . postMessage ( { type : 'audio' , data : pcmData } ) ;
105-
106- if ( gainNode . current ) {
107- const now = audioContext . current . currentTime ;
108- gainNode . current . gain . cancelScheduledValues ( now ) ;
109- gainNode . current . gain . setValueAtTime (
110- isAudioMuted ? 0 : volume ,
111- audioContext . current . currentTime ,
112- ) ;
113- }
96+ try {
97+ const blob = convertBase64ToBlob ( message . data ) ;
98+ const arrayBuffer = await blob . arrayBuffer ( ) ;
99+ const audioBuffer =
100+ await audioContext . current . decodeAudioData ( arrayBuffer ) ;
114101
115- setIsPlaying ( true ) ;
116- onPlayAudio . current ( message . id ) ;
117- } catch ( e ) {
118- const eMessage = e instanceof Error ? e . message : 'Unknown error' ;
119- onError . current ( `Failed to add clip to queue: ${ eMessage } ` ) ;
120- }
121- } ,
122- [ isAudioMuted , volume ] ,
123- ) ;
102+ const pcmData = audioBuffer . getChannelData ( 0 ) ;
103+ workletNode . current ?. port . postMessage ( { type : 'audio' , data : pcmData } ) ;
104+
105+ setIsPlaying ( true ) ;
106+ onPlayAudio . current ( message . id ) ;
107+ } catch ( e ) {
108+ const eMessage = e instanceof Error ? e . message : 'Unknown error' ;
109+ onError . current ( `Failed to add clip to queue: ${ eMessage } ` ) ;
110+ }
111+ } , [ ] ) ;
124112
125113 const stopAll = useCallback ( ( ) => {
126114 isInitialized . current = false ;
0 commit comments