hmm
This commit is contained in:
54
script.js
54
script.js
@@ -2077,21 +2077,49 @@ function initListenerMode() {
|
|||||||
document.body.classList.add('listening-active'); // For global CSS targeting
|
document.body.classList.add('listening-active'); // For global CSS targeting
|
||||||
updateGlowIntensity(settings.glowIntensity || 30);
|
updateGlowIntensity(settings.glowIntensity || 30);
|
||||||
|
|
||||||
// Setup Audio Context for volume/routing
|
// Setup Audio Context for volume/routing (only if not already created)
|
||||||
listenerAudioContext = new (window.AudioContext || window.webkitAudioContext)();
|
if (!listenerAudioContext) {
|
||||||
listenerGainNode = listenerAudioContext.createGain();
|
listenerAudioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
listenerGainNode.gain.value = 0.8;
|
listenerGainNode = listenerAudioContext.createGain();
|
||||||
listenerGainNode.connect(listenerAudioContext.destination);
|
listenerGainNode.gain.value = 0.8;
|
||||||
|
listenerGainNode.connect(listenerAudioContext.destination);
|
||||||
|
console.log('🎵 Created new AudioContext for listener mode');
|
||||||
|
} else {
|
||||||
|
console.log('♻️ Reusing existing AudioContext');
|
||||||
|
}
|
||||||
|
|
||||||
// Create a hidden audio element to handle the MediaSource
|
// Create or reuse audio element to handle the MediaSource
|
||||||
const audio = new Audio();
|
let audio;
|
||||||
audio.autoplay = false; // Don't autoplay - we use the Enable Audio button
|
if (window.listenerAudio) {
|
||||||
audio.hidden = true;
|
// Reuse existing audio element from previous initialization
|
||||||
document.body.appendChild(audio);
|
audio = window.listenerAudio;
|
||||||
|
console.log('♻️ Reusing existing audio element');
|
||||||
|
|
||||||
// Bridge Audio Element to AudioContext
|
// Clean up old MediaSource if it exists
|
||||||
const sourceNode = listenerAudioContext.createMediaElementSource(audio);
|
if (audio.src) {
|
||||||
sourceNode.connect(listenerGainNode);
|
URL.revokeObjectURL(audio.src);
|
||||||
|
audio.removeAttribute('src');
|
||||||
|
audio.load(); // Reset the element
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Create a new hidden audio element
|
||||||
|
audio = new Audio();
|
||||||
|
audio.autoplay = false; // Don't autoplay - we use the Enable Audio button
|
||||||
|
audio.hidden = true;
|
||||||
|
document.body.appendChild(audio);
|
||||||
|
console.log('🆕 Created new audio element');
|
||||||
|
|
||||||
|
// Bridge Audio Element to AudioContext (only for new elements)
|
||||||
|
// Note: createMediaElementSource can only be called once per audio element
|
||||||
|
try {
|
||||||
|
const sourceNode = listenerAudioContext.createMediaElementSource(audio);
|
||||||
|
sourceNode.connect(listenerGainNode);
|
||||||
|
console.log('🔗 Connected audio element to AudioContext');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('❌ Failed to create MediaElementSource:', e.message);
|
||||||
|
// This is a critical error, but continue anyway
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize MediaSource for streaming binary chunks
|
// Initialize MediaSource for streaming binary chunks
|
||||||
const mediaSource = new MediaSource();
|
const mediaSource = new MediaSource();
|
||||||
|
|||||||
Reference in New Issue
Block a user