/** * Electron Audio Path Debug Script * Run this in the console to debug audio path issues in Electron */ function debugElectronAudioPaths() { console.log('šŸ”§ Electron Audio Path Debug'); console.log('=' .repeat(50)); console.log('Environment Info:'); console.log('- Is Electron:', window.electronAPI !== undefined); console.log('- Current URL:', window.location.href); console.log('- Current Protocol:', window.location.protocol); console.log('- Current Directory:', window.location.href.replace('/index.html', '')); // Test basic audio creation console.log('\nšŸŽµ Testing Basic Audio Creation:'); try { const testAudio = new Audio(); console.log('āœ… Audio element created successfully'); console.log('- Initial src:', testAudio.src); // Test setting a simple relative path testAudio.src = 'audio/tasks/teasing/u.mp3'; console.log('- After setting relative path:', testAudio.src); // Test setting an absolute file path const absolutePath = window.location.href.replace('/index.html', '') + '/audio/tasks/teasing/u.mp3'; testAudio.src = absolutePath; console.log('- After setting absolute path:', testAudio.src); testAudio.src = ''; } catch (error) { console.error('āŒ Error creating audio element:', error); } // Test actual file access console.log('\nšŸ“ Testing File Access:'); const testPaths = [ 'audio/tasks/teasing/u.mp3', './audio/tasks/teasing/u.mp3', window.location.href.replace('/index.html', '') + '/audio/tasks/teasing/u.mp3' ]; testPaths.forEach((path, index) => { console.log(`\nTest ${index + 1}: ${path}`); const audio = new Audio(); audio.addEventListener('loadstart', () => { console.log(` āœ… Load started for: ${path}`); }); audio.addEventListener('canplay', () => { console.log(` āœ… Can play: ${path}`); audio.src = ''; // Clean up }); audio.addEventListener('error', (e) => { console.log(` āŒ Error loading: ${path}`); console.log(` Error details:`, { error: e.target.error, src: e.target.src, networkState: e.target.networkState, readyState: e.target.readyState }); }); try { audio.src = path; setTimeout(() => { if (audio.readyState === 0 && audio.networkState !== 2) { console.log(` ā° Timeout for: ${path}`); } }, 2000); } catch (error) { console.log(` āŒ Exception setting src: ${error.message}`); } }); // Test if electronAPI is available and working if (window.electronAPI) { console.log('\n⚔ Testing Electron API:'); window.electronAPI.fileExists('audio/tasks/teasing/u.mp3').then(exists => { console.log('- File exists (relative):', exists); }).catch(err => { console.log('- Error checking file existence:', err); }); window.electronAPI.getAppPath().then(appPath => { console.log('- App path:', appPath); }).catch(err => { console.log('- Error getting app path:', err); }); } } // Auto-run the debug console.log('šŸ”§ Electron Audio Debug loaded. Running automatic test...'); debugElectronAudioPaths(); // Make function available globally window.debugElectronAudioPaths = debugElectronAudioPaths;