-
Notifications
You must be signed in to change notification settings - Fork 128
/
Audio_Music_Player.js
59 lines (52 loc) · 1.19 KB
/
Audio_Music_Player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { dialog } = require('electron').remote;
const { app } = require('electron');
const path = require('path');
const { spawn } = require('child_process');
// Function to select a file
function selectFile() {
const file = dialog.showOpenDialogSync({
title: 'Select an audio file',
filters: [
{ name: 'Audio Files', extensions: ['mp3', 'wav', 'ogg'] }
]
});
if (file && file.length > 0) {
return file[0];
}
return '';
}
// Function to play the selected file
function playMusic(filePath) {
const player = spawn('ffplay', ['-nodisp', '-autoexit', filePath]);
player.on('exit', () => {
player.kill();
});
}
// Function to stop the music
function stopMusic() {
spawn('taskkill', ['/IM', 'ffplay.exe', '/F']);
}
let filePath = selectFile();
if (filePath) {
playMusic(filePath);
}
while (true) {
console.log('1. Select a file');
console.log('2. Stop music');
console.log('3. Exit');
const choice = prompt('Enter your choice: ');
switch (choice) {
case '1':
filePath = selectFile();
if (filePath) {
playMusic(filePath);
}
break;
case '2':
stopMusic();
break;
case '3':
app.quit();
break;
}
}