Extension exports
MUDE Music Player does not currently export a public API for use by other extensions. All functionality is accessed through VS Code commands.Extension lifecycle
Activation
The extension activates automatically when VS Code starts (onStartupFinished activation event).
Activation sequence:
- Creates global storage directory if it doesn’t exist
- Starts the MPV player instance
- Registers all commands and status bar items
- Attempts to restore the last played track from the previous session
- Sets up the UI in either playing or stopped state
Deactivation
- Quits the MPV player instance
- Preserves playback state for the next session
Internal events
MUDE uses the MPV player’s event system to handle playback changes.Player events
| Event | Trigger | Behavior |
|---|---|---|
stopped | Track finishes playing | Automatically loads and plays the next recommended track |
pause | Playback is paused | Updates status bar to show play icon |
resume | Playback is resumed | Updates status bar to show pause icon |
- Status bar updates to show “Loading next track…”
- Extension checks if recommendations are available
- If available, downloads and plays the next track
- If unavailable, shows “Search for more songs to play!” message
State management
The extension uses VS Code’sglobalState API to persist data across sessions.
Stored state
| Key | Type | Description |
|---|---|---|
youtubeLabelButton | string | Current track title shown in status bar |
lastPlayedFilePath | string | Path to the last downloaded track file |
recommendations | array | List of recommended tracks for continuous playback |
currentRecommendationIndex | number | Index of the current track in recommendations |
youtubeSearchHistory | array | List of recently played tracks (max 5 items) |
currentPick | object | Currently selected track information |
isPlaying | boolean | Whether music is currently playing |
Status bar integration
The extension creates several status bar items for playback control:- Track label: Shows the currently playing track name
- Play/Pause button: Toggles playback state
- Previous button: Plays the previous track
- Next button: Plays the next track
- Seek backward button: Skips backward 10 seconds
- Seek forward button: Skips forward 10 seconds
- Playing state: All controls visible, pause icon shown
- Stopped state: Only search and track label visible
File storage
MUDE stores downloaded tracks in VS Code’s global storage directory:- Each new download overwrites the previous file
- Only one track is stored at a time
- File persists across VS Code restarts for playback restoration
Dependencies
MUDE relies on several external dependencies:Required system dependencies
- MPV: Media player for audio playback (must be on system PATH)
Node.js dependencies
- node-mpv: Node.js interface for MPV player
- youtube-dl-exec: Downloads audio from YouTube
- ytmusic-api: Searches YouTube Music and fetches recommendations
Extension commands for internal use
These commands are used internally for UI updates:extension.refreshYoutubeLabelButton: Updates the track label in status barextension.refreshRecommendations: Refreshes the recommendations list
Error handling
Common error scenarios:- MPV not found: Shows error modal with installation instructions
- No media loaded: Shows information message when trying to control playback
- Download fails: Updates status bar with error message and returns to stopped state
- No recommendations available: Prompts user to search for more songs
Integration examples
Assigning keyboard shortcuts
Add to yourkeybindings.json: