I'm currently working on building an Audio Player using Electron and Web Audio API. The method I have in place for opening and playing audio files is as follows:
The user selects audio files through a native dialog window which then loads the file paths to local storage (application store)
Upon clicking a "play button", the file is read and converted to array buffer for compatibility with Web Audio API.
const buffer = toArrayBuffer(fs.readFileSync(filePath));
const audioBuffer = await ctx.decodeAudioData(buffer);
const soundNode = new AudioBufferSourceNode(ctx, { buffer:
audioBuffer });
While this process usually works adequately, it tends to slow down significantly when dealing with files over 5MB. In fact, opening a 9MB file took around 3 seconds, which is not acceptable. This has led me to some additional questions.
- Would preloading audio files to local storage during step 1 (open dialog) help improve efficiency?
- Could it be that Electron combined with Web Audio API is not efficient enough to support a desktop player that operates smoothly with local files? (I certainly hope not)