trying to fix bug

This commit is contained in:
2026-04-09 01:36:28 -06:00
parent f9cd2bf579
commit 1d17a8f19a
10 changed files with 133 additions and 27 deletions

View File

@ -67,19 +67,27 @@ export default function WaveformTimeline({ cutMode, muteMode }: { cutMode: boole
setAudioError(null);
const loadAudio = async () => {
const requestId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
try {
const waveformUrl = `${backendUrl}/audio/waveform?path=${encodeURIComponent(videoPath!)}`;
console.log('[WaveformTimeline] backendUrl:', backendUrl, '| videoPath:', videoPath);
console.log('[WaveformTimeline] Fetching:', waveformUrl);
console.log('[WaveformTimeline] req=', requestId, 'backendUrl=', backendUrl, 'videoPath=', videoPath);
console.log('[WaveformTimeline] req=', requestId, 'fetching=', waveformUrl);
const ctx = new AudioContext();
audioContextRef.current = ctx;
const startedAt = performance.now();
const response = await fetch(waveformUrl);
const elapsedMs = Math.round(performance.now() - startedAt);
if (!response.ok) {
const body = await response.text().catch(() => '');
console.error(
`[WaveformTimeline] Fetch failed — HTTP ${response.status} ${response.statusText}`,
{ url: waveformUrl, body }
`[WaveformTimeline] req=${requestId} fetch failed — HTTP ${response.status} ${response.statusText}`,
{
url: waveformUrl,
decodedPath: videoPath,
elapsedMs,
body,
}
);
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
@ -87,11 +95,11 @@ export default function WaveformTimeline({ cutMode, muteMode }: { cutMode: boole
const contentType = response.headers.get('content-type') ?? 'unknown';
const contentLength = response.headers.get('content-length');
console.log(
`[WaveformTimeline] Fetch OK — content-type: ${contentType}, size: ${contentLength ?? 'unknown'} bytes`
`[WaveformTimeline] req=${requestId} fetch ok — content-type: ${contentType}, size: ${contentLength ?? 'unknown'} bytes, elapsed: ${elapsedMs}ms`
);
const arrayBuffer = await response.arrayBuffer();
console.log(`[WaveformTimeline] ArrayBuffer size: ${arrayBuffer.byteLength} bytes`);
console.log(`[WaveformTimeline] req=${requestId} arrayBuffer size: ${arrayBuffer.byteLength} bytes`);
if (arrayBuffer.byteLength === 0) {
throw new Error('Server returned an empty file');
@ -104,6 +112,7 @@ export default function WaveformTimeline({ cutMode, muteMode }: { cutMode: boole
console.error(
'[WaveformTimeline] decodeAudioData failed — browser cannot decode this format.',
{
requestId,
contentType,
byteLength: arrayBuffer.byteLength,
videoPath,
@ -117,13 +126,19 @@ export default function WaveformTimeline({ cutMode, muteMode }: { cutMode: boole
}
console.log(
`[WaveformTimeline] Decoded OK — duration: ${audioBuffer.duration.toFixed(2)}s, ` +
`[WaveformTimeline] req=${requestId} decoded ok — duration: ${audioBuffer.duration.toFixed(2)}s, ` +
`channels: ${audioBuffer.numberOfChannels}, sampleRate: ${audioBuffer.sampleRate}Hz`
);
audioBufferRef.current = audioBuffer;
drawStaticWaveform();
} catch (err) {
console.error('[WaveformTimeline] Waveform load failed:', err);
console.error('[WaveformTimeline] waveform load failed', {
requestId,
error: err,
videoPath,
backendUrl,
encodedPath: encodeURIComponent(videoPath ?? ''),
});
const waveformUrl2 = `${backendUrl}/audio/waveform?path=${encodeURIComponent(videoPath ?? '')}`;
setAudioError(`Waveform unavailable — ${err instanceof Error ? err.message : 'audio could not be decoded'} [URL: ${waveformUrl2}]`);
}