I’m trying to build a game to android, ios and desktop. The issue I’m having is that ios uses dom audio and android uses web audio (or the other way round not important). If I use the wrong type of audio file on an OS the sound simply won’t play. To get round this issue I’m trying to load the audio files from the resources folder as its possible to set whether it uses web audio or dom audio during load as described at the bottom of http://docs.cocos2d-x.org/creator/manual/en/asset-workflow/audio-asset.html
Currently I’ve got this code:
public static AddAudioSource(file : string, node : cc.Node)
{
file = "resources/Sound/" + file + ".mp3";
cc.loader.load(file, this.LoadAudio.bind(null, node));
}
In my callback this function returns an HTMLAudioElement as the second parameter.
private static LoadAudio = (node : cc.Node, error, sound : HTMLAudioElement) =>
{
console.log("load", sound);
}
How can I turn this element into a audio clip or similar for use on a component? Or perhaps is there another way to get the sound to work cross platform?