top of page
bottom of page
${data.researchSummary || 'No research summary available.'}
`; } } catch (err) { console.error('Mix Player: Failed to load episode', err); document.getElementById('episode-title').textContent = 'Failed to load podcast'; } } function attachEventListeners() { const audio = document.getElementById('mix-audio'); const playBtn = document.getElementById('mix-play-btn'); const progress = document.getElementById('mix-progress'); const speedSelect = document.getElementById('mix-speed'); // Play/Pause playBtn.addEventListener('click', () => { if (audio.paused) { audio.play(); playBtn.innerHTML = '❚❚'; } else { audio.pause(); playBtn.innerHTML = '▶'; } }); // Progress bar audio.addEventListener('timeupdate', () => { const percent = (audio.currentTime / audio.duration) * 100; progress.style.width = percent + '%'; }); // Speed control speedSelect.addEventListener('change', () => { audio.playbackRate = parseFloat(speedSelect.value); }); } // Auto-initialize when script loads function initialize() { initConfig(); createPlayer(); } // Initialize immediately initialize(); })(); // ============================================= // BODY END: Cleanup, Public API & Finalization // ============================================= // Expose a public API for advanced users const MixPlayer = { version: SCRIPT_VERSION, play: function() { const audio = document.getElementById('mix-audio'); if (audio) audio.play(); }, pause: function() { const audio = document.getElementById('mix-audio'); if (audio) audio.pause(); }, setSpeed: function(speed) { const audio = document.getElementById('mix-audio'); if (audio && speed >= 0.5 && speed <= 3.0) { audio.playbackRate = speed; const select = document.getElementById('mix-speed'); if (select) select.value = speed; } }, loadEpisode: function(podcastId) { config.podcastId = podcastId; loadEpisode(podcastId); }, destroy: function() { const player = document.getElementById('mix-player'); if (player) player.remove(); }, on: function(event, callback) { // Simple event system (expandable) if (event === 'ready') { // Trigger immediately for now setTimeout(() => callback(), 100); } } }; // Attach public API to window window.MixPlayer = MixPlayer; // Error handling wrapper function safeExecute(fn, errorMsg) { try { fn(); } catch (error) { console.error(`[MixPlayer] ${errorMsg}:`, error); } } // Graceful initialization with error boundary function safeInitialize() { try { initConfig(); createPlayer(); console.log(`%c🎙️ MixPlayer v${SCRIPT_VERSION} initialized successfully`, 'color: #00ff9d; font-weight: bold;'); } catch (error) { console.error('[MixPlayer] Failed to initialize:', error); // Fallback: Show minimal error message in container const container = document.getElementById('mix-player-container'); if (container) { container.innerHTML = `