forked from computertech/techdj
hmm
This commit is contained in:
36
script.js
36
script.js
@@ -2077,21 +2077,49 @@ function initListenerMode() {
|
||||
document.body.classList.add('listening-active'); // For global CSS targeting
|
||||
updateGlowIntensity(settings.glowIntensity || 30);
|
||||
|
||||
// Setup Audio Context for volume/routing
|
||||
// Setup Audio Context for volume/routing (only if not already created)
|
||||
if (!listenerAudioContext) {
|
||||
listenerAudioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
listenerGainNode = listenerAudioContext.createGain();
|
||||
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
|
||||
const audio = new Audio();
|
||||
// Create or reuse audio element to handle the MediaSource
|
||||
let audio;
|
||||
if (window.listenerAudio) {
|
||||
// Reuse existing audio element from previous initialization
|
||||
audio = window.listenerAudio;
|
||||
console.log('♻️ Reusing existing audio element');
|
||||
|
||||
// Clean up old MediaSource if it exists
|
||||
if (audio.src) {
|
||||
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
|
||||
// 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
|
||||
const mediaSource = new MediaSource();
|
||||
|
||||
Reference in New Issue
Block a user