playsoundwithvlc
v1.0.0
Published
Play & Stop Sound in Node JS Applications using VLC
Downloads
3
Maintainers
Readme
Play Sound With VLC Media PLayer
Why I Built this ?
I was building another package called cliclock and I needed to play sound when the timer ends. So tried to play sound then I played sound but then I failed to stop it.
Then I spent a few days asking ChatGPT for solution and it gave this solution.
I just prompted it.
Installation
npm install playsoundwithvlc
How to Use
import { playSound, stopSound } from "playsoundwithvlc";
const filePaths = {
vlcExePath: "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe",
audioPath: "C:\\Users\\Sooraj\\Desktop\\audio.mp3",
};
playSound(filePaths.vlcExePath, filePaths.audioPath);
setTimeout(() => {
stopSound();
}, 5000);
Source Code
import { spawn } from "child_process";
let playerProcess;
// Function to play sound
function playSound(vlcExePath, audioPath) {
// Spawn the VLC player process
playerProcess = spawn(vlcExePath, ["--intf", "dummy", audioPath]);
}
// Function to stop sound playback
function stopSound() {
if (playerProcess) {
// Send a SIGTERM signal to terminate the process
playerProcess.kill("SIGTERM");
}
}
export { playSound, stopSound };