trying to fix bug
This commit is contained in:
@ -23,6 +23,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
|
||||
const IS_ELECTRON = !!window.electronAPI;
|
||||
const LAST_MEDIA_PATH_KEY = 'talkedit:lastMediaPath';
|
||||
|
||||
type Panel = 'ai' | 'settings' | 'export' | 'silence' | null;
|
||||
|
||||
@ -74,6 +75,23 @@ export default function App() {
|
||||
// The backend URL is fixed at 127.0.0.1:8000 so we rely on the store default.
|
||||
}, [setBackendUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!IS_ELECTRON || videoPath) return;
|
||||
const savedPath = sessionStorage.getItem(LAST_MEDIA_PATH_KEY);
|
||||
if (savedPath) {
|
||||
loadVideo(savedPath);
|
||||
}
|
||||
}, [videoPath, loadVideo]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!IS_ELECTRON) return;
|
||||
if (videoPath) {
|
||||
sessionStorage.setItem(LAST_MEDIA_PATH_KEY, videoPath);
|
||||
return;
|
||||
}
|
||||
sessionStorage.removeItem(LAST_MEDIA_PATH_KEY);
|
||||
}, [videoPath]);
|
||||
|
||||
const handleLoadProject = async () => {
|
||||
if (!IS_ELECTRON) return;
|
||||
try {
|
||||
|
||||
@ -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}]`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user