Reputation: 4853
I'm trying to launch VLC in Electron using child_process
:
const { app, BrowserWindow } = require('electron');
const child = require('child_process');
require('electron-reload')();
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
win.loadFile('index.html');
}
function launchVLC () {
var proc = child.spawn("vlc");
}
app.whenReady().then(createWindow).then(launchVLC);
After running:
npm run start
I'm getting a ENOENT error:
I'm using Windows 10.
What I'm doing wrong?
Upvotes: 1
Views: 749
Reputation: 2694
You need to specify the correct path to the program. As the error says, the path doesn't exist:
main.js
const path = require('path')
function getDefaultVlcPath () {
if (process.platform === 'win32') {
return path.join('C:', 'Program Files (x86)', 'VideoLAN', 'VLC', 'vlc.exe')
}
else if (process.platform === 'linux') {
return '/usr/bin/vlc'
}
else if (process.platform === 'darwin') {
return '/Applications/VLC.app/Contents/MacOS/VLC'
}
}
function getVlcPath () {
// If the user specified custom VLC path
// use that instead of the default one
if (settings.customVlcPath) {
return settings.customVlcPath
}
else {
return getDefaultVlcPath()
}
}
child.spawn(getVlcPath())
yourSettingsFile.json
{
settings.customVlcPath: 'specified/custom/path/to/vlc'
}
Upvotes: 1