goldfire / howler.js

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

no audio under the WeChat Mini Games platform #983

Open obiot opened 6 years ago

obiot commented 6 years ago

When running under WeChat Mini Games, using the Web Adapter, the WeChat Console log throws the following error :

HTMLAudioElement.load() is not implemented.

Which points to the following line : https://github.com/goldfire/howler.js/blob/master/src/howler.core.js#L2056

I tried to do a quick and dirty patch by replacing the call to load() by self._state = 'loaded', but this does not work.

Forcing to HTML5 Audio does not help either.

I have not further investigated it for now, so just opening a ticket here, at least for awareness.

goldfire commented 6 years ago

So am I right in understanding that WeChat isn't implementing actual HTML5 Audio, but something that just looks similar with a bit different API?

obiot commented 6 years ago

so it's a bit more complicated than this (of course, else it would not be funny).

1) WeChat actually does implement some sort of subset of the Web Audio API, but it requires a proprietary call to wx.createInnerAudioContext() and then does not implement everything (like gain for example). See below for the documentation, it's in Chinese, but the example they show basically covers the full extend of the current API. https://developers.weixin.qq.com/minigame/dev/tutorial/ability/audio.html

2) In an attempt to add a compatibility layer with most of the existing HTML5 engine, the WeChat engineers came up with basically a wrapper (https://github.com/finscn/weapp-adapter/blob/master/README_EN.md) on top of the native WeChat API, and this one adds a pseudo HTML5 Audio implementation that itself is missing a couple of things, like the load function (https://github.com/finscn/weapp-adapter/blob/master/src/Audio.js#L66). So loading isnot really required in the first place by WeChat, but the lack of it does not really please Howler.

FYI, I use the below for deployment under WeChat, which works perfectly :

let au = new Audio('http://url/to/audio.mp3');
au.play();
au.pause();

Not sure though which way should be added into Howler : the native implementation, or rely on the wrapper and support the light HTML5 Audio.

obiot commented 6 years ago

if you point me to your preferred "direction" I can try to submit a PR for it.