Skip to content

Instantly share code, notes, and snippets.

@GuillaumeNachury
Created June 9, 2017 12:49
Show Gist options
  • Save GuillaumeNachury/9888728cc982e5a369b1c4662414c654 to your computer and use it in GitHub Desktop.
Save GuillaumeNachury/9888728cc982e5a369b1c4662414c654 to your computer and use it in GitHub Desktop.
Mac OS terminal music player
const fs = require('fs');
const spawn = require('child_process').spawn;
var files = [];
fs.readdir('./', (err, data) => {
files = data.filter((f)=> f.match('mp3') != null);
playRandomFile();
});
function playRandomFile(){
var f = files[(Math.random() * files.length) | 0];
console.log("\x1b[42m\x1b[1m\x1b[31m [i] Playing: %s\x1b[0m",f);
var player = spawn('afplay', [f]).on('close', (code) => {
playRandomFile();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment