diff --git a/script.js b/script.js index 871caf6..d803097 100644 --- a/script.js +++ b/script.js @@ -2133,8 +2133,18 @@ function initListenerMode() { mediaSource.addEventListener('sourceopen', () => { console.log('📦 MediaSource opened'); + const mimeType = 'audio/webm;codecs=opus'; + + if (!MediaSource.isTypeSupported(mimeType)) { + console.error(`❌ Browser does not support ${mimeType}`); + const statusEl = document.getElementById('connection-status'); + if (statusEl) statusEl.textContent = '❌ Error: Browser does not support WebM/Opus audio'; + alert('Your browser does not support WebM/Opus audio format. Please try Chrome, Firefox, or Edge.'); + return; + } + try { - sourceBuffer = mediaSource.addSourceBuffer('audio/webm;codecs=opus'); + sourceBuffer = mediaSource.addSourceBuffer(mimeType); sourceBuffer.mode = 'sequence'; // Kick off first append if data is already in queue @@ -2337,7 +2347,9 @@ async function enableListenerAudio() { // If no buffered data yet, wait a bit for it to arrive if (!hasBufferedData()) { console.log('⏳ Waiting for audio data to buffer...'); - if (audioText) audioText.textContent = 'WAITING FOR STREAM...'; + if (audioText) { + audioText.textContent = chunksReceived > 0 ? 'BUFFERING...' : 'WAITING FOR STREAM...'; + } // Wait up to 10 seconds for data to arrive (increased from 5) const waitForData = new Promise((resolve) => { @@ -2347,6 +2359,10 @@ async function enableListenerAudio() { const checkInterval = setInterval(() => { attempts++; + if (audioText && chunksReceived > 0 && audioText.textContent === 'WAITING FOR STREAM...') { + audioText.textContent = 'BUFFERING...'; + } + if (attempts % 10 === 0) { // Log every second console.log(`⏱️ Attempt ${attempts}/${maxAttempts} - Buffered: ${window.listenerAudio.buffered.length}, ReadyState: ${window.listenerAudio.readyState}`); }