trying to switch how audio is playing

This commit is contained in:
JISAUAY committed 2024-10-24 09:20:23 -05:00
1 parent e17e02f517
commit f331b7f9d3
3 files changed
+66 -23

No files matched your search

+3 -1
View File
@@ -14,8 +14,10 @@
"electron": "^33.0.1" "electron": "^33.0.1"
}, },
"dependencies": { "dependencies": {
"fluent-ffmpeg": "^2.1.3",
"id3js": "^2.1.1", "id3js": "^2.1.1",
"mp3-duration": "^1.1.0", "mp3-duration": "^1.1.0",
"node-id3": "^0.2.6" "node-id3": "^0.2.6",
"speaker": "^0.5.5"
} }
} }
+28
View File
@@ -14,9 +14,33 @@ import { fileURLToPath } from 'node:url';
import NodeID3 from 'node-id3'; import NodeID3 from 'node-id3';
import fs from 'node:fs'; import fs from 'node:fs';
import ffmpeg from 'fluent-ffmpeg';
import Speaker from 'speaker';
let win; 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 createWindow = () => {
const filename = fileURLToPath(import.meta.url); const filename = fileURLToPath(import.meta.url);
@@ -89,6 +113,10 @@ ipcMain.handle('getAudioInfo', function(event, path) {
return id3tags; return id3tags;
}); });
ipcMain.handle('playSong', (event, path) => {
let command = ffmpeg(path);
});
// function getAudioInfo(url) { // function getAudioInfo(url) {
// let info; // let info;
+35 -22
View File
@@ -7,8 +7,17 @@ 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
// 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; let library;
@@ -43,9 +52,9 @@ async function readChildren(path) {
let child = dirChildren[i]; let child = dirChildren[i];
if (child.isDirectory) { if (child.isDirectory) {
let dirPath = child.path + child.name; let dirPath = child.path + '/' + child.name;
let dirChildren = await readChildren(dirPath); // let dirChildren = await readChildren(dirPath);
children.push(new Dir(dirPath, dirChildren)); children.push(new Dir(dirPath, []));
} else { } else {
children.push(child); children.push(child);
} }
@@ -75,9 +84,9 @@ document.addEventListener('DOMContentLoaded', async () => {
const filename = e.name; const filename = e.name;
if (e instanceof Dir) { if (e instanceof Dir) {
libContentDisplay.innerHTML += `<div class="LibDir" id=${i}>- ${filename}</div`; libContentDisplay.innerHTML += `<div class="LibDir" isOpen="0" path="${e.path}">- ${filename}</div`;
} else { } else {
libContentDisplay.innerHTML += `<div class="LibEntry" id="${i}">${filename}</div>`; libContentDisplay.innerHTML += `<div class="LibEntry" path="${e.path + '/' + e.name}">${filename}</div>`;
} }
} }
}); });
@@ -86,11 +95,10 @@ document.addEventListener('DOMContentLoaded', async () => {
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
const libContentDisplay = document.getElementById('libContents'); const libContentDisplay = document.getElementById('libContents');
libContentDisplay.addEventListener('click', (e) => { libContentDisplay.addEventListener('click', async (e) => {
if (e.target.className == 'LibEntry') { if (e.target.className == 'LibEntry') {
console.log(e); console.log(e.target.attributes);
let file_id = parseInt(e.target.id); let audioPath = e.target.attributes.getNamedItem('path').value;
let audioPath = libEntryPathes[file_id].path + libEntryPathes[file_id].name;
console.log(`Audio Path: ${audioPath}`); console.log(`Audio Path: ${audioPath}`);
@@ -108,26 +116,31 @@ document.addEventListener('DOMContentLoaded', async () => {
} else if (e.target.className == 'LibDir') { } else if (e.target.className == 'LibDir') {
let id = parseInt(e.target.id); let id = parseInt(e.target.id);
let dir = library.children[id]; let dirPath = e.target.attributes.getNamedItem('path').value;
let dirName = dirPath.split('/').at(-1);
let isOpen = e.target.attributes.getNamedItem('isOpen');
if (!dir.open) { if (!parseInt(isOpen.value)) {
e.target.innerHTML = `+ ${dir.name}`; e.target.innerHTML = `+ ${dirName}`;
for (const i in dir.children) { let dirChildren = await readChildren(dirPath);
let entry = dir.children[i];
if (entry.isDirectory) { for (const i in dirChildren) {
e.target.innerHTML += `<div class="LibDir" id="">${entry.name}</div>` let entry = dirChildren[i];
if (entry instanceof Dir) {
e.target.innerHTML += `<div class="LibDir" path="${entry.path}" isOpen="0">- ${entry.name}</div>`
} else { } else {
e.target.innerHTML += `<div class="LibEntry">${entry.name}</div>` e.target.innerHTML += `<div class="LibEntry" path="${entry.path + '/' + entry.name}">${entry.name}</div>`
} }
} }
dir.open = true; isOpen.value = "1";
} else { } else {
e.target.innerHTML = `- ${dir.name}`; e.target.innerHTML = `- ${dirName}`;
dir.open = false; isOpen.value = "0";
} }
e.target.attributes.setNamedItem(isOpen);
} }
}); });
}); });