Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/mayur1377/MUDE-music-in-vscode/llms.txt

Use this file to discover all available pages before exploring further.

MUDE automatically creates playlists for you using YouTube Music’s recommendation algorithm, ensuring uninterrupted music playback while you code.

How it works

When you select a track to play, MUDE automatically fetches recommendations and builds a playlist queue:
// Fetch recommendations immediately after track selection
const newRecommendations = await getRecommendations(ytmusicurl);
newRecommendations.forEach(addRecommendation);

Recommendation flow

  1. Search and select: Choose a track from search results
  2. Fetch recommendations: MUDE queries YouTube Music for related tracks
  3. Build queue: Recommendations are added to the playlist queue
  4. Auto-play: When current track ends, next recommendation plays automatically
Recommendations are fetched using YouTube Music’s “Up Next” algorithm, which considers your currently playing track to suggest similar music.

YouTube Music API integration

MUDE uses the ytmusic-api package to fetch recommendations:
import YTMusic from "ytmusic-api";
const ytmusic = new YTMusic();

export const getRecommendations = async (videoUrl: string) => {
  const videoId = videoUrl.split('v=')[1];
  
  await ytmusic.initialize();
  const upNexts = await ytmusic.getUpNexts(videoId);
  
  return upNexts;
};

Recommendation structure

Each recommendation contains:
{
  videoId: string,  // YouTube video ID
  title: string     // Track title
}
Recommendations are stored both in memory and in VS Code’s global state, ensuring they persist across window reloads.

Queue management

The playlist queue is managed through a simple index-based system:

Current index tracking

export let recommendations: { videoId: string, title: string }[] = [];
export let currentRecommendationIndex = 0;
export function addRecommendation(recommendation: { videoId: string, title: string }) {
  recommendations.push(recommendation);
}
New recommendations are appended to the end of the queue.

Automatic playback

When a track finishes playing, MUDE automatically plays the next recommendation:
player.on('stopped', async () => {
  if (currentRecommendationIndex < recommendations.length) {
    const nextRecommendation = recommendations[currentRecommendationIndex];
    updateRecommendationIndex(currentRecommendationIndex + 1);
    
    let ytmusicurl = `https://music.youtube.com/watch?v=${nextRecommendation.videoId}`;
    await processTrack(context, ytmusicurl, nextRecommendation.title, ytmusicurl);
  } else {
    vscode.window.showInformationMessage('Search for more songs to play!');
  }
});
The automatic playback system ensures you never experience silence while coding. When the queue is exhausted, you’ll be prompted to search for more music.
You can manually navigate through the recommendation queue:

Next track

if (currentRecommendationIndex < recommendations.length) {
  const nextRecommendation = recommendations[currentRecommendationIndex];
  updateRecommendationIndex(currentRecommendationIndex + 1);
  await processTrack(context, ytmusicurl, nextRecommendation.title, ytmusicurl);
} else {
  vscode.window.showWarningMessage("No more tracks next in playlist or recommendations.");
}

Previous track

if (currentRecommendationIndex > 0) {
  const prevRecommendation = recommendations[currentRecommendationIndex - 1];
  updateRecommendationIndex(currentRecommendationIndex - 1);
  await processTrack(context, ytmusicurl, prevRecommendation.title, ytmusicurl);
} else {
  vscode.window.showWarningMessage("No tracks beyond in playlist or recommendations.");
}
The previous track feature allows you to replay tracks from earlier in your session, not just the immediately previous track.

Status bar integration

The status bar displays helpful information about your queue:

Smart tooltips

Playback control buttons show context-aware tooltips:
// Next button tooltip
function getNextRecommendationTooltip(): string {
  const nextIndex = currentRecommendationIndex;
  if (nextIndex < recommendations.length) {
    return `Up next: ${recommendations[nextIndex].title}`;
  }
  return 'Play next';
}

// Previous button tooltip
function getPreviousRecommendationTooltip(): string {
  const prevIndex = currentRecommendationIndex - 1;
  if (prevIndex >= 0) {
    return `Play previous: ${recommendations[prevIndex].title}`;
  }
  return 'Play previous';
}
Tooltips update dynamically as you navigate through the queue, always showing you what track will play next or previous.

State persistence

Recommendations and queue position are persisted across VS Code sessions:
// Save to global state
await context.globalState.update('recommendations', recommendations);
await context.globalState.update('currentRecommendationIndex', currentRecommendationIndex);

// Restore on activation
const savedRecommendations = context.globalState.get('recommendations', []);
const savedIndex = context.globalState.get('currentRecommendationIndex', 0);

Cross-window synchronization

When you have multiple VS Code windows open, recommendations are synchronized:
vscode.window.onDidChangeWindowState(() => {
  vscode.commands.executeCommand('extension.refreshRecommendations');
});
If you switch between VS Code windows, your playlist queue and current position are automatically synchronized.

End of queue behavior

When you reach the end of the recommendation queue:
  1. Playback stops gracefully
  2. Status bar controls hide
  3. Information message prompts: “Search for more songs to play!”
  4. Search button remains visible for easy access
You can start a new playlist session anytime by clicking the search button (🎧 icon) in the status bar.

Build docs developers (and LLMs) love