Guy
Guy

Reputation: 535

Howler throws 'Decoding audio data failed' when used inside electron

I'm trying to load an audio file using Howler.js inside an Electron app, on the renderer process.

new Howl({
  src: ['/path/to/audio/file.mp3'] 
)}

However, no matter what file type I'm trying to load, it always throws the same error inside Howler's loaderror event:

Decoding audio data failed.

I'm using Parcel to build a React based front end.
When I tried to remove them and start a new Electron project, loading & playing the audio files, from the same path, worked fine.

Those are the build commands:

"dev": "concurrently --kill-others --success first \"npm run parcel-dev\" \"npm run electron-dev\"",
"parcel-dev": "parcel ./src/index.html -d build/",
"electron-dev": "electron . --start-dev",

Upvotes: 0

Views: 1319

Answers (1)

Drew Bradley
Drew Bradley

Reputation: 31

I ran into a similar issue in my React app. I was able to fix it by importing the sound file at the top of the JavaScript file and passing the alias into the function.

import { Howl } from 'howler';
import soundFile from './sound-file.mp3'


export const sound = new Howl ({
  src: [soundFile],
  onload() {
    console.log("Sound is loaded.")
  },
  onloaderror(msg){
    console.log("NO SOUND!!!", msg)
  }
})

Upvotes: 2

Related Questions