diff --git a/package.json b/package.json index d24f713..7553fa3 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,10 @@ "electron": "^33.0.1" }, "dependencies": { + "fluent-ffmpeg": "^2.1.3", "id3js": "^2.1.1", "mp3-duration": "^1.1.0", - "node-id3": "^0.2.6" + "node-id3": "^0.2.6", + "speaker": "^0.5.5" } } diff --git a/src/main.js b/src/main.js index c5a5632..5f3028b 100644 --- a/src/main.js +++ b/src/main.js @@ -14,9 +14,33 @@ import { fileURLToPath } from 'node:url'; import NodeID3 from 'node-id3'; import fs from 'node:fs'; +import ffmpeg from 'fluent-ffmpeg'; +import Speaker from 'speaker'; let win; +class MusicPlayer { + constructor(path) { + this.songPath = path; + this.playing = false; + this.progress = 0; + + this.speaker = new Speaker({ + channels: 2, + bitDepth: 16, + sampleRate: 44100 + }); + } + + play(path) { + if (path != null) { + this.songPath = path; + } + + let stream = fs.create + } +} + const createWindow = () => { const filename = fileURLToPath(import.meta.url); @@ -89,6 +113,10 @@ ipcMain.handle('getAudioInfo', function(event, path) { return id3tags; }); +ipcMain.handle('playSong', (event, path) => { + let command = ffmpeg(path); +}); + // function getAudioInfo(url) { // let info; diff --git a/src/renderer.js b/src/renderer.js index 80b7a2d..720c3ec 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -7,8 +7,17 @@ console.log('test'); // const url = 'file://C:\\Users\\JISAUAY\\Documents\\misc\\sspm\\test.ogg'; // const path = 'C:\\Users\\JISAUAY\\Documents\\misc\\sspm\\ChangelingForest.mp3'; -// const libPath = 'C:/Users/JISAUAY/Documents/misc/sspm/test-library/'; -const libPath = '/home/jackson/Documents/code/SSPM/test-library/' +const libPath = 'C:/Users/JISAUAY/Documents/misc/sspm/test-library/'; +// const libPath = '/home/jackson/Documents/code/SSPM/test-library/' + +// Play Raw data to speaker +// https://github.com/TooTallNate/node-speaker + +// Get Raw Data with Ffmpeg +// https://github.com/fluent-ffmpeg/node-fluent-ffmpeg?tab=readme-ov-file + +// FFMpeg command for pcm data +// ffmpeg -i input.whatever -f s16le -acodec pcm_s16le output.pcm let library; @@ -43,9 +52,9 @@ async function readChildren(path) { let child = dirChildren[i]; if (child.isDirectory) { - let dirPath = child.path + child.name; - let dirChildren = await readChildren(dirPath); - children.push(new Dir(dirPath, dirChildren)); + let dirPath = child.path + '/' + child.name; + // let dirChildren = await readChildren(dirPath); + children.push(new Dir(dirPath, [])); } else { children.push(child); } @@ -75,9 +84,9 @@ document.addEventListener('DOMContentLoaded', async () => { const filename = e.name; if (e instanceof Dir) { - libContentDisplay.innerHTML += `