MCPcopy
hub / github.com/jamiepine/voicebox / LandingAudioPlayer

Function LandingAudioPlayer

landing/src/components/LandingAudioPlayer.tsx:65–298  ·  view source on GitHub ↗
({
  audioUrl,
  title,
  playing,
  muted,
  onFinish,
  onClose,
}: LandingAudioPlayerProps)

Source from the content-addressed store, hash-verified

63}
64
65export function LandingAudioPlayer({
66 audioUrl,
67 title,
68 playing,
69 muted,
70 onFinish,
71 onClose,
72}: LandingAudioPlayerProps) {
73 const waveformRef = useRef<HTMLDivElement>(null);
74 const wavesurferRef = useRef<WaveSurfer | null>(null);
75 const [isPlaying, setIsPlaying] = useState(false);
76 const [currentTime, setCurrentTime] = useState(0);
77 const [duration, setDuration] = useState(0);
78 const [volume, setVolume] = useState(0.75);
79 const [isLooping, setIsLooping] = useState(false);
80 const [isReady, setIsReady] = useState(false);
81 const onFinishRef = useRef(onFinish);
82 onFinishRef.current = onFinish;
83 const playingRef = useRef(playing);
84 playingRef.current = playing;
85 const mutedRef = useRef(muted);
86 mutedRef.current = muted;
87
88 // Initialize WaveSurfer
89 useEffect(() => {
90 const initWaveSurfer = () => {
91 const container = waveformRef.current;
92 if (!container) {
93 setTimeout(initWaveSurfer, 50);
94 return;
95 }
96
97 const rect = container.getBoundingClientRect();
98 if (rect.width === 0 || rect.height === 0) {
99 setTimeout(initWaveSurfer, 50);
100 return;
101 }
102
103 // Clean up existing instance
104 if (wavesurferRef.current) {
105 wavesurferRef.current.destroy();
106 wavesurferRef.current = null;
107 }
108
109 const root = document.documentElement;
110 const getCSSVar = (varName: string) => {
111 const value = getComputedStyle(root).getPropertyValue(varName).trim();
112 return value ? `hsl(${value})` : '';
113 };
114
115 const ws = WaveSurfer.create({
116 container,
117 waveColor: getCSSVar('--muted'),
118 progressColor: getCSSVar('--accent'),
119 cursorColor: getCSSVar('--accent'),
120 barWidth: 2,
121 barRadius: 2,
122 height: 80,

Callers

nothing calls this directly

Calls 3

catchMethod · 0.80
thenMethod · 0.80
formatDurationFunction · 0.70

Tested by

no test coverage detected