Skip to main content

Timeline for Load locally saved files to tonejs

Current License: CC BY-SA 4.0

5 events
when toggle format what by license comment
Jul 3 at 16:26 comment added geekonaut That doesn't work, because readFileSync defaults to reading the data as a string. Use fs.readFileSync(rscPath + '/samples/piano/A4.mp3', {encoding: 'buffer') instead.
Jul 3 at 15:36 comment added FallenAngel7882 I tried following those steps with the following code: let buffer = fs.readFileSync(rscPath + "/samples/piano/A4.mp3") const view = new Uint8Array(buffer).buffer; console.log(view) let player = new Tone.Player(view).toDestination(); Tone.loaded().then(() => { player.start(); }) but i just get the following error: Debug.js:17 Uncaught (in promise) RangeError: Value must be within [0, Infinity], got: NaN
Jul 3 at 10:22 comment added geekonaut Ah, I misinterpreted the original question. I assumed you were trying to have users select a file and play it back. Works roughly like that: 1. Read the data with fs.readFile or fs.readFileSync etc. with encoding set to buffer 2. Turn the buffer into an ArrayBuffer 3. Pass ArrayBuffer into Tone.Player constructor
Jul 3 at 8:30 comment added FallenAngel7882 So the idea is that i have my source code in src folder, and my audio files in another folder. Would this work if i were to use fileReader.readAsArrayBuffer("path/to/file.mp3")? Or maybe by reading the file to a Buffer and passing the buffer to the file reader?
Jul 3 at 8:26 history answered geekonaut CC BY-SA 4.0