@@ -2,6 +2,7 @@ import type { FC, PropsWithChildren } from 'react';
22import { useCallback , useEffect } from 'react' ;
33
44import { Sound , Volume } from '@nuclearplayer/hifi' ;
5+ import { usePlatform } from '@nuclearplayer/ui' ;
56
67import { useCoreSetting } from '../hooks/useCoreSetting' ;
78import { eventBus } from '../services/eventBus' ;
@@ -10,6 +11,11 @@ import { useQueueStore } from '../stores/queueStore';
1011import { useSoundStore } from '../stores/soundStore' ;
1112import { resolveErrorMessage } from '../utils/logging' ;
1213
14+ // WebKitGTK's Web Audio GStreamer pipeline is hardcoded to 44100 Hz, which
15+ // causes silent audio over Bluetooth A2DP (PipeWire sinks expect 48000 Hz).
16+ // Forcing the AudioContext to 48000 Hz on Linux avoids the mismatch.
17+ const LINUX_SAMPLE_RATE_HZ = 48000 ;
18+
1319export const SoundProvider : FC < PropsWithChildren > = ( { children } ) => {
1420 const { src, status, seek } = useSoundStore ( ) ;
1521 const [ crossfadeMs ] = useCoreSetting < number > ( 'playback.crossfadeMs' ) ;
@@ -18,6 +24,8 @@ export const SoundProvider: FC<PropsWithChildren> = ({ children }) => {
1824 const [ volume01 ] = useCoreSetting < number > ( 'playback.volume' ) ;
1925 const [ muted ] = useCoreSetting < boolean > ( 'playback.muted' ) ;
2026 const volumePercent = muted ? 0 : Math . round ( ( volume01 ?? 1 ) * 100 ) ;
27+ const platform = usePlatform ( ) ;
28+ const sampleRate = platform === 'linux' ? LINUX_SAMPLE_RATE_HZ : undefined ;
2129
2230 useEffect ( ( ) => {
2331 if ( crossfadeMs !== undefined ) {
@@ -71,6 +79,7 @@ export const SoundProvider: FC<PropsWithChildren> = ({ children }) => {
7179 status = { status }
7280 seek = { seek }
7381 volume = { volumePercent }
82+ sampleRate = { sampleRate }
7483 preload = { preload }
7584 crossOrigin = { crossOrigin }
7685 onTimeUpdate = { handleTimeUpdate }
0 commit comments