The La Urban Radio Player features an intelligent lyrics system that automatically searches for and displays synchronized lyrics from LRCLIB. The system handles mid-song joins, adaptive timing compensation, and silent operation when lyrics aren’t available.
The core lyrics functionality is handled by the LyricsManager class in js/lyrics.js:
class LyricsManager { constructor() { this.lyrics = []; // Array of {time, text} objects this.currentIndex = -1; // Current displayed lyric this.timeOffset = 0; // Initial song elapsed time this.songStartTimestamp = null; // When song started this.useVirtualTime = false; // Use Azura time vs audio time this.updateInterval = null; // Update timer this.customDelay = null; // Platform-specific delay }}
The system automatically compensates for streaming latency with platform-specific delays:
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);const LYRICS_CONFIG = { // iOS Safari has aggressive buffering STREAM_DELAY: isIOS ? 4.5 : 1.5, UPDATE_INTERVAL: 100 // Update every 100ms for smooth transitions};
iOS Optimization: iPhone and iPad devices receive a 4.5-second delay compensation due to Safari’s aggressive audio buffering, while desktop and Android use 1.5 seconds.
The lyrics system operates silently to avoid cluttering the user experience:
Automatic Mode
Manual Mode
When songs change automatically, the system searches silently:
// Called when song changesif (currentSongId !== state.lastSongId) { // Clear previous lyrics immediately if (state.lyricsManager) { state.lyricsManager.clear(); } // Search for new lyrics in silent mode (no console logs) fetchAndLoadLyrics(artist, title, duration, elapsed, true);}
Silent mode behavior:
✅ No console logs
✅ No error messages if lyrics not found
✅ Clean cover display when unavailable
✅ Automatic retry on song change
Developers can manually search with detailed logging:
// From browser consolesearchCurrentSongLyrics()// Output:// 🔍 Buscando letras para: Bad Bunny - Monaco// ⏱️ Tiempo transcurrido: 5.23s de 175s// ✅ Letras cargadas: 42 líneas (inicio en 5.23s)// 🎤 LETRAS SINCRONIZADAS
The system exposes helpful console commands for debugging:
Search Current Song
Adjust Delay
Clear Lyrics
Demo Mode
// Search lyrics for currently playing songsearchCurrentSongLyrics()// Output includes:// - Artist and title// - Elapsed time and duration// - Number of lyric lines found// - Synchronization status
// Get current delay settinggetLyricsDelay()// Returns: "Current lyrics delay: 1.5s"// Set custom delay (in seconds)setLyricsDelay(2.0) // Increase if lyrics appear too earlysetLyricsDelay(1.0) // Decrease if lyrics appear too late// Then refresh lyricssearchCurrentSongLyrics()
// Manually clear displayed lyricsclearLyrics()
// Load demo lyrics for testingconst demoLyrics = LyricsManager.getDemoLyrics();state.lyricsManager.loadLyrics(demoLyrics);