Closed watabou closed 2 years ago
Hm, it looks like Howler.js doesn't support this kind of functionality at all...
Any success with this? I also need to load ogg/m4a from ByteArray in html target, so failed using Sound.loadCompressedDataFromByteArray
🤔
There is a risk that loading bytes directly may be a format that the current browser does not understand, but it appears the functionality for this exists internally in howler
Something sort of like: (but I don't think this would work outside of the howler.js script)
var howl = new Howl ();
Howler.ctx.decodeAudioData(arraybuffer, function(buffer) {
if (buffer) {
loadSound(howl, buffer);
}
});
I think the way this would work (if Howler supported raw bytes) would be adding an alternative to the src
property, like arraybuffer
, which it would use instead of loading from the source, then call this sort of thing internally
Thank you @jgranick, that is helpful. I think we can also use base64 conversion (which is immediately supported by howlerjs) as that goes through the same functionality. I will take that path first as a workaround.
Hello, here is my trick to get ogg bytes to work with Howlerjs:
var b64content = 'data:audio/ogg;base64,' + Base64.encode(bytes);
var buffer = AudioBuffer.fromFile(b64content);
var sound = Sound.fromAudioBuffer(buffer);
buffer.src.on("load", function() {
//sound ready
});
That might help someone else, just beware you have to wait Howl to respond. 😊
@zatarus Did your workaround really work on HTML5? Do you have a working sample? I'm wondering because the onLoad event never fires and even if it does how do I actually start playback?
@scanline, this is exactly how I made it work, I didn't have any issues at all. Are you sure onload never fires? That is mapped to Howler's load function, please put a trace there to see if it fires and make sure your file is in ogg format.
Don't mind me, just cleaning up old solved issues.
Code like this:
crashes with a log like this:
Apparently
AudioBuffer.__srcHowl
doesn't get initialized.