Created
June 9, 2017 12:49
-
-
Save GuillaumeNachury/9888728cc982e5a369b1c4662414c654 to your computer and use it in GitHub Desktop.
Mac OS terminal music player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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