forked from computertech/techdj
hmm
This commit is contained in:
34
script.js
34
script.js
@@ -2097,6 +2097,12 @@ function initListenerMode() {
|
|||||||
const mediaSource = new MediaSource();
|
const mediaSource = new MediaSource();
|
||||||
audio.src = URL.createObjectURL(mediaSource);
|
audio.src = URL.createObjectURL(mediaSource);
|
||||||
|
|
||||||
|
// CRITICAL: Call load() to initialize the MediaSource
|
||||||
|
// Without this, the audio element won't load the MediaSource until play() is called,
|
||||||
|
// which will fail with "no supported sources" if no data is buffered yet
|
||||||
|
audio.load();
|
||||||
|
console.log('🎬 Audio element loading MediaSource...');
|
||||||
|
|
||||||
let sourceBuffer = null;
|
let sourceBuffer = null;
|
||||||
let audioQueue = [];
|
let audioQueue = [];
|
||||||
let chunksReceived = 0;
|
let chunksReceived = 0;
|
||||||
@@ -2271,8 +2277,16 @@ async function enableListenerAudio() {
|
|||||||
console.log('✅ Audio context resumed');
|
console.log('✅ Audio context resumed');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Wait for buffered data before attempting playback
|
// 3. Prepare and start audio playback
|
||||||
if (window.listenerAudio) {
|
if (window.listenerAudio) {
|
||||||
|
console.log('📊 Audio element state:', {
|
||||||
|
readyState: window.listenerAudio.readyState,
|
||||||
|
networkState: window.listenerAudio.networkState,
|
||||||
|
src: window.listenerAudio.src ? 'set' : 'not set',
|
||||||
|
buffered: window.listenerAudio.buffered.length,
|
||||||
|
paused: window.listenerAudio.paused
|
||||||
|
});
|
||||||
|
|
||||||
// Unmute just in case
|
// Unmute just in case
|
||||||
window.listenerAudio.muted = false;
|
window.listenerAudio.muted = false;
|
||||||
window.listenerAudio.volume = settings.volume || 0.8;
|
window.listenerAudio.volume = settings.volume || 0.8;
|
||||||
@@ -2282,33 +2296,43 @@ async function enableListenerAudio() {
|
|||||||
return window.listenerAudio.buffered && window.listenerAudio.buffered.length > 0;
|
return window.listenerAudio.buffered && window.listenerAudio.buffered.length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If no buffered data yet, wait a bit for it to arrive
|
||||||
if (!hasBufferedData()) {
|
if (!hasBufferedData()) {
|
||||||
console.log('⏳ Waiting for audio data to buffer...');
|
console.log('⏳ Waiting for audio data to buffer...');
|
||||||
if (audioText) audioText.textContent = 'WAITING FOR STREAM...';
|
if (audioText) audioText.textContent = 'WAITING FOR STREAM...';
|
||||||
|
|
||||||
// Wait up to 5 seconds for data to arrive
|
// Wait up to 10 seconds for data to arrive (increased from 5)
|
||||||
const waitForData = new Promise((resolve, reject) => {
|
const waitForData = new Promise((resolve) => {
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
const maxAttempts = 50; // 5 seconds (50 * 100ms)
|
const maxAttempts = 100; // 10 seconds (100 * 100ms)
|
||||||
|
|
||||||
const checkInterval = setInterval(() => {
|
const checkInterval = setInterval(() => {
|
||||||
attempts++;
|
attempts++;
|
||||||
|
|
||||||
|
if (attempts % 10 === 0) { // Log every second
|
||||||
|
console.log(`⏱️ Attempt ${attempts}/${maxAttempts} - Buffered: ${window.listenerAudio.buffered.length}, ReadyState: ${window.listenerAudio.readyState}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasBufferedData()) {
|
if (hasBufferedData()) {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
console.log('✅ Audio data buffered, ready to play');
|
console.log('✅ Audio data buffered, ready to play');
|
||||||
resolve();
|
resolve();
|
||||||
} else if (attempts >= maxAttempts) {
|
} else if (attempts >= maxAttempts) {
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
reject(new Error('Timeout waiting for audio data'));
|
// Don't reject - try to play anyway, MediaSource might handle it
|
||||||
|
console.warn('⚠️ Timeout waiting for buffered data, attempting playback anyway...');
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitForData;
|
await waitForData;
|
||||||
|
} else {
|
||||||
|
console.log('✅ Audio already has buffered data');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt playback
|
// Attempt playback
|
||||||
|
console.log('▶️ Attempting to play audio...');
|
||||||
await window.listenerAudio.play();
|
await window.listenerAudio.play();
|
||||||
console.log('✅ Audio playback started successfully');
|
console.log('✅ Audio playback started successfully');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user