Inspiration
One day, I realized I had been feeling unproductive for several days. After a quick self-reflection, I discovered that watching TV series and movies in the background while coding was draining my focus and creativity.
This insight inspired me to build a tool—for myself and others—to stay focused with relaxing ambient music.
This guide helps you set up, build, test, and contribute to the Ambient Music AutoPlayer extension for Visual Studio Code.
ambient-music-vs-extension/
├── .vscode/ # Debug configs for dev mode
├── dist/ # Compiled JS output (built via TypeScript)
├── media/ # YouTube HTML player
├── src/ # Main TypeScript source code
│ ├── extension.ts # Entry point (activate/deactivate)
│ ├── commands.ts # VS Code command registration
│ ├── playlist.ts # Playlist management
│ ├── serverManager.ts # Singleton HTTP server
│ ├── webSocketManager.ts# Singleton WebSocket logic
│ └── utils/ # Helper functions (browser, config, logger)
├── test/ # Mocha-based test suite
├── package.json # VS Code extension manifest
├── tsconfig.json # TypeScript configuration
└── README.md # End-user instructions
git clone https://github.com/taj54/ambient-music-vs-extension.git
cd ambient-music-vs-extensionnpm installnpm run compile- Open the project in VS Code
- Press
F5to start a new Extension Development Host
Expected:
- Ambient YouTube music auto-launches in a browser tab
- WebSocket connects and displays confirmation
- The extension spins up a local HTTP server that serves a YouTube-based HTML client (
media/client.html) - A WebSocket connection allows the extension to send commands (play, pause, switch track, close tab)
- Music auto-plays when VS Code opens a workspace
- Track rotation happens every X minutes (default 30)
| Component | Responsibility |
|---|---|
serverManager.ts |
HTTP server with singleton pattern |
webSocketManager.ts |
WebSocket communication (client commands + rotation) |
playlist.ts |
Load/parse/manage YouTube video playlist |
browser.ts |
Open/close browser tabs (Chrome) |
extension.ts |
Entry point – activates server, WebSocket, commands |
commands.ts |
Exposes VS Code command palette actions |
Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and search for:
| Command ID | Title | Description |
|---|---|---|
ambientMusic.setPlaylist |
🎶 Set Playlist (Rain, Forest, Ocean...) | Choose or define a relaxing playlist |
ambientMusic.openTab |
🌐 Open Ambient Music Player | Opens the embedded music player tab |
ambientMusic.play |
Starts playing ambient music | |
ambientMusic.pause |
⏸️ Pause Music | Pauses the currently playing track |
ambientMusic.resume |
⏯ Resume Music | Resumes paused ambient music |
ambientMusic.closeTab |
❌ Close Music Player | Closes the music player tab |
ambientMusic.resetPlaylist |
🔄 Reset Playlist to Default | Restores the default ambient playlist |
💡 Tip: You can customize keybindings for these commands or use them in your automation workflows inside VS Code.
These settings can be customized in your VS Code settings.json.
| Setting Key | Type | Default | Description |
|---|---|---|---|
ambientMusic.autoPlayOnStartup |
boolean |
true |
Automatically start ambient music when VS Code launches. |
ambientMusic.port |
number |
3303 |
Port for the WebSocket server. Set to 0 for dynamic port allocation. |
ambientMusic.switchIntervalMinutes |
number |
30 |
Time interval (in minutes) to automatically switch to the next video in the playlist. |
ambientMusic.debug |
boolean |
false |
Enables verbose debug logging for easier troubleshooting. |
ambientMusic.playlist |
array |
[] |
Custom list of ambient YouTube videos with rich metadata. See example below. |
{
"title": "Peaceful Piano",
"url": "https://youtu.be/abc123",
"tags": ["piano", "relax"],
"channel": {
"name": "Chill Music Co.",
"url": "https://youtube.com/@chillmusicco"
}
}
ℹ️ Use these to personalize your flow.
The extension will auto-switch to the next track based on:
startRotation(clientUrl, intervalMinutes);npm install -g vsce
vsce packageYou’ll get a .vsix file that can be installed or published to the VS Code Marketplace.
- Run
npm run test(uses@vscode/test-electron) - Watch WebSocket & HTTP logs in VS Code terminal
- Debug client with DevTools → right-click → Inspect on the player tab
To prevent multiple instances, a .ambient-music-extension.lock file is created at runtime.
On extension deactivate or VS Code close, this lock is removed.
- Node.js v18+
- VS Code v1.80+
- Chrome installed (for tab open/close logic)
See CONTRIBUTING.md