function spawn (playerPath, url, title) { if (playerPath != null) return spawnExternal(playerPath, [url]) // Try to find and use VLC if external player is not specified vlcCommand(function (err, vlcPath) { if (err) return windows.main.dispatch('externalPlayerNotFound') const args = [ '--play-and-exit', '--video-on-top', '--quiet', `--meta-title=${JSON.stringify(title)}`, url ] spawnExternal(vlcPath, args) }) }
initVLC(servingUrl: string) { vlcCommand((error, cmd: string) => { if (error) return console.error('Could not find vlc command path'); if (process.platform === 'win32') { childProcess.execFile(cmd, [servingUrl], (_error, stdout) => { if (_error) return console.error(_error); return console.log(stdout); }); } else { childProcess.exec(`${cmd} ${servingUrl}`, (_error, stdout) => { if (_error) return console.error(_error); return console.log(stdout); }); } this.powerSaveBlockerId = powerSaveBlocker.start( 'prevent-app-suspension' ); return true; }); }
// Spawns VLC with child_process.spawn() to return a ChildProcess object // Calls back with (err, childProcess) function spawn (args, cb) { vlcCommand(function (err, vlcPath) { if (err) return cb(err) cb(null, cp.spawn(vlcPath, args)) }) }
// Finds if VLC is installed on Mac, Windows, or Linux. // Calls back with true or false: whether VLC was detected function checkForVLC (cb) { vlcCommand((err) => cb(!err)) }
function onSelection (index) { href = (argv.airplay || argv.chromecast || argv.xbmc) ? 'http://' + networkAddress() + ':' + server.address().port + '/' + index : 'http://localhost:' + server.address().port + '/' + index if (playerName) torrent.files[index].select() if (argv.stdout) torrent.files[index].createReadStream().pipe(process.stdout) var cmd if (argv.vlc) { vlcCommand(function (err, cmd) { if (err) return fatalError(err) if (process.platform === 'win32') { var args = [].concat(href, VLC_ARGS.split(' ')) unref(cp.execFile(cmd, args, function (err) { if (err) return fatalError(err) torrentDone() }).on('exit', gracefulExit)) } else { unref(cp.exec(cmd + ' ' + href + ' ' + VLC_ARGS, function (err) { if (err) return fatalError(err) torrentDone() }).on('exit', gracefulExit)) } }) } else if (argv.mplayer) { cmd = MPLAYER_EXEC + ' ' + href } else if (argv.mpv) { cmd = MPV_EXEC + ' ' + href } else if (argv.omx) { cmd = OMX_EXEC + ' ' + href } if (cmd) { unref(cp.exec(cmd, function (err) { if (err) return fatalError(err) torrentDone() }).on('exit', gracefulExit)) } if (argv.airplay) { var airplay = require('airplay-js') airplay.createBrowser() .on('deviceOn', function (device) { device.play(href, 0, function () {}) }) .start() } if (argv.chromecast) { var chromecasts = require('chromecasts')() chromecasts.on('update', function (player) { player.play(href, { title: torrent.name }) player.on('error', function (err) { err.message = 'Chromecast: ' + err.message errorAndExit(err) }) }) } if (argv.xbmc) { var xbmc = require('nodebmc') new xbmc.Browser() .on('deviceOn', function (device) { device.play(href, function () {}) }) } drawTorrent(torrent) }
function checkInstall (playerPath, cb) { // check for VLC if external player has not been specified by the user // otherwise assume the player is installed if (playerPath == null) return vlcCommand(cb) process.nextTick(() => cb(null)) }