goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
24.05k stars 2.24k forks source link

howler with HTMLMediaElement.src #1239

Open Racheli86 opened 5 years ago

Racheli86 commented 5 years ago

I'm trying to play audio which is not a file such as --> src: ['sound.webm', 'sound.mp3'] (as far as I understand). The audio is HTMLMediaElement.src type. It's not working at the moment and I would really appreciate some help here :) Thanks.

Here is part of the code: playSong(response, volume){ const blob = new Blob([response as any], { type: 'audio/mpeg' }); const objectUrl = URL.createObjectURL(blob); const audio = new Audio(); audio.src = objectUrl; let read = new Howl ({ src:['audio.src' ], html5: true, //volume: this.scan_volume ,//this.scan_volume, //default }); console.log("i'm in!") read.volume(volume); read.play(); }

suterma commented 2 years ago

Why are you creating the Audio object? You could just use the objectUrl, in conjunction with the format option. See

https://github.com/goldfire/howler.js/issues/436#issue-129650455

Does this help? The documentation about this is lacking, but I can confirm that using objectUrl's do work with the correct format option.

@goldfire I suggest to close this, and improve the doc, as also suggested by https://github.com/goldfire/howler.js/issues/1485#issuecomment-1002112642 for example