diff --git a/src/index.html b/src/index.html index 922cc50..c4806d2 100644 --- a/src/index.html +++ b/src/index.html @@ -12,11 +12,18 @@ content="default-src 'self'; script-src 'self'" /> Menu + -
Library
-
+
+ + +
+
+

Library

+
+
+
- diff --git a/src/renderer.js b/src/renderer.js index 1b87c47..a6b5b9d 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -7,7 +7,11 @@ 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 = './test-library/' +const libPath = './test-library/'; + +let libEntryPathes; + +let currentlyPlaying; // const player = new Audio(url); @@ -24,14 +28,52 @@ async function getLibraryFiles() { document.addEventListener('DOMContentLoaded', async () => { const libContentDisplay = document.getElementById('libContents'); - let files = await getLibraryFiles(); - console.log(files); + libEntryPathes = await getLibraryFiles(); + console.log(libEntryPathes); - for (const file_i in files) { - libContentDisplay.innerHTML += `
${files[file_i]}
`; + for (const file_i in libEntryPathes) { + libContentDisplay.innerHTML += `
${libEntryPathes[file_i]}
`; } }); +document.addEventListener('DOMContentLoaded', () => { + const libContentDisplay = document.getElementById('libContents'); + + libContentDisplay.addEventListener('click', (e) => { + if (e.target.className == 'LibEntry') { + console.log(e); + let file_id = parseInt(e.target.id); + let audioPath = '../' + libPath + libEntryPathes[file_id]; + + console.log(`Audio Path: ${audioPath}`); + + currentlyPlaying = new Audio(audioPath); + currentlyPlaying.play() + .catch(e => { + console.error(`Audio failed to play with ${e}`); + }); + } + }); +}); + +document.addEventListener('DOMContentLoaded', () => { + document.getElementById('play').addEventListener('click', playMedia); + document.getElementById('pause').addEventListener('click', pauseMedia); +}); + + +function pauseMedia() { + if (currentlyPlaying !== null) { + currentlyPlaying.pause(); + } +} + +function playMedia() { + if (currentlyPlaying !== null) { + currentlyPlaying.play(); + } +} + // fromUrl(url).then((tags) => { // console.log(tags); // });