This implementation adds real-time music visualization to the Matrix digital rain effect using the Spotify Web API.
- OAuth 2.0 Authentication: Secure popup-based authentication flow
- Real-time Track Data: Fetches currently playing track information every 5 seconds
- Audio Features: Analyzes tempo, energy, danceability, and valence
- Token Management: Automatic token refresh and secure localStorage storage
- Corner Minimap: Configurable position (top-left, top-right, bottom-left, bottom-right)
- Track Information: Displays song title, artist, and album art
- Audio Features Display: Shows energy, tempo, danceability, and mood percentages
- Animated Bars: 16-bar spectrum visualization based on audio features
- Beat Pulse Effect: Synchronizes with track tempo
- Dynamic Colors: Music influences the color palette based on mood (valence)
- Speed Modulation: Tempo and energy affect animation and fall speed
- Brightness Control: Energy levels modify overall brightness and cursor intensity
- Beat Reactions: Bloom effects pulse with the music beat
- Configurable Sensitivity: Adjustable influence strength (0.1x to 3.0x)
- Visit the Spotify Developer Dashboard
- Create a new app or use an existing one
- Add your Matrix site URL to the app's redirect URIs (e.g.,
http://localhost:8000/) - Copy the Client ID
- Open the Matrix rain visualization
- Click the Spotify (♪) icon in the top-left corner to expand the controls
- Paste your Spotify Client ID in the "Client ID" field
- Click "Connect" to authenticate with Spotify
- Authorize the app in the popup window
- Sync Matrix with Music: Check this to make the Matrix effect respond to your music
- Show Visualizer: Toggle the corner minimap on/off
- Visualizer Position: Choose where to display the minimap
You can configure Spotify features via URL parameters:
?spotifyEnabled=true # Enable Spotify integration
&spotifyClientId=your_client_id # Pre-fill client ID
&musicSync=true # Enable music synchronization
&musicSensitivity=1.5 # Set sensitivity (0.1-3.0)
&musicColors=true # Enable color influence
&musicSpeed=true # Enable speed influence
&musicBrightness=true # Enable brightness influence
&visualizer=true # Show visualizer
&visualizerPos=bottom-right # Set visualizer position
When music synchronization is enabled, the following Matrix parameters are modified:
- Animation Speed: Scales with tempo (normalized to 120 BPM) and energy
- Fall Speed: Increases with energy level
- Cycle Speed: Faster glyph changes with higher energy
- Brightness: Energy and valence boost overall brightness
- Cursor Intensity: Scales with energy level
- Bloom Strength: Pulses with beat detection
- Raindrop Length: Influenced by danceability
- Palette Hue: Shifts based on valence (mood) - happy songs shift toward warmer colors
- Cursor Color: Hue shifts with track mood
- Saturation/Lightness: Energy affects color intensity
js/spotify.js- Spotify Web API integration and OAuth handlingjs/visualizer.js- Music visualizer minimap componentjs/spotify-ui.js- User interface controls and settingsjs/music-integration.js- Matrix parameter modification based on audio features- Updates to
js/main.jsandjs/config.js
- Uses Spotify Web API endpoints:
/v1/me/player/currently-playing- Get current track/v1/audio-features/{id}- Get audio analysis
- Implements proper rate limiting and error handling
- Caches audio features to minimize API calls
- Completely optional - works without affecting core Matrix functionality
- Graceful fallback when no music is playing
- No external dependencies beyond existing Matrix libraries
- Client ID is stored locally (localStorage)
- Tokens are stored securely in localStorage
- No server-side components required
- Popup-based OAuth prevents credential exposure
- Ensure your Client ID is correct
- Check that your domain is added to Spotify app redirect URIs
- Verify popup blockers aren't preventing authentication
- Make sure Spotify is playing music in the same browser
- Check that your Spotify account has premium features (if required)
- Try refreshing the connection if data stops updating
- Music synchronization updates parameters 10 times per second
- Disable features you don't need to reduce CPU usage
- Visualizer can be hidden while keeping music sync active