got the audio streams kind of working
This commit is contained in:
1 parent
f331b7f9d3
commit
7af998f0bc
2 files changed
+49
-9
No files matched your search
+47
-7
@@ -16,6 +16,7 @@ import NodeID3 from 'node-id3';
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
import Speaker from 'speaker';
|
import Speaker from 'speaker';
|
||||||
|
import Stream from 'node:stream';
|
||||||
|
|
||||||
let win;
|
let win;
|
||||||
|
|
||||||
@@ -23,13 +24,12 @@ class MusicPlayer {
|
|||||||
constructor(path) {
|
constructor(path) {
|
||||||
this.songPath = path;
|
this.songPath = path;
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.progress = 0;
|
this.progress = 0; // in seconds
|
||||||
|
this.duration = null;
|
||||||
|
this.audioStream = null;
|
||||||
|
|
||||||
this.speaker = new Speaker({
|
this.speaker = new Speaker();
|
||||||
channels: 2,
|
this.timer = null;
|
||||||
bitDepth: 16,
|
|
||||||
sampleRate: 44100
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
play(path) {
|
play(path) {
|
||||||
@@ -37,7 +37,44 @@ class MusicPlayer {
|
|||||||
this.songPath = path;
|
this.songPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream = fs.create
|
if (this.audioStream != null) {
|
||||||
|
if (!this.audioStream.ended) {
|
||||||
|
this.audioStream.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.audioStream = this.transcode(this.songPath);
|
||||||
|
|
||||||
|
this.audioStream.pipe(this.speaker);
|
||||||
|
|
||||||
|
this.timer = setInterval(() => {
|
||||||
|
this.progress += 0.5;
|
||||||
|
|
||||||
|
if (this.progress >= this.duration) {
|
||||||
|
clearInterval(this.timer);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// To pause close and don't? flush
|
||||||
|
pause() {
|
||||||
|
// this.speaker.close(false);
|
||||||
|
this.audioStream.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
transcode(input) {
|
||||||
|
const s = new Stream.PassThrough();
|
||||||
|
|
||||||
|
ffmpeg(input)
|
||||||
|
.on('codecData', (data) => {
|
||||||
|
this.duration = data.duration;
|
||||||
|
})
|
||||||
|
.audioCodec('pcm_s16le')
|
||||||
|
.format('s16le')
|
||||||
|
.pipe(s);
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +92,9 @@ const createWindow = () => {
|
|||||||
|
|
||||||
win.loadFile('src/index.html');
|
win.loadFile('src/index.html');
|
||||||
// enable(win.webContents);
|
// enable(win.webContents);
|
||||||
|
|
||||||
|
let player = new MusicPlayer('/home/jackson/Documents/code/SSPM/test-library/test.mp3');
|
||||||
|
player.play();
|
||||||
};
|
};
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
|
|||||||
+2
-2
@@ -7,8 +7,8 @@ console.log('test');
|
|||||||
|
|
||||||
// const url = 'file://C:\\Users\\JISAUAY\\Documents\\misc\\sspm\\test.ogg';
|
// const url = 'file://C:\\Users\\JISAUAY\\Documents\\misc\\sspm\\test.ogg';
|
||||||
// const path = 'C:\\Users\\JISAUAY\\Documents\\misc\\sspm\\ChangelingForest.mp3';
|
// const path = 'C:\\Users\\JISAUAY\\Documents\\misc\\sspm\\ChangelingForest.mp3';
|
||||||
const libPath = 'C:/Users/JISAUAY/Documents/misc/sspm/test-library/';
|
// const libPath = 'C:/Users/JISAUAY/Documents/misc/sspm/test-library/';
|
||||||
// const libPath = '/home/jackson/Documents/code/SSPM/test-library/'
|
const libPath = '/home/jackson/Documents/code/SSPM/test-library/';
|
||||||
|
|
||||||
// Play Raw data to speaker
|
// Play Raw data to speaker
|
||||||
// https://github.com/TooTallNate/node-speaker
|
// https://github.com/TooTallNate/node-speaker
|
||||||
|
|||||||
Reference in new issue
Block a user