1

I have searched high and low for several days for this problem and I just can't figure it out, hopefully someone else has solved this.

The problem is simple, I have created a web-based game using mainly createjs, preloadjs, and soundjs. The plan was to load the content inside a UIWebView on iOS and WebView on Android to create the two apps.

The problem occurs on Android 4.4 and lower. Neither the videos or the sounds are playing. I'm starting with the simplest scenario; I have an image on a web page, attached a preloaded sound to play onclick;

init:

createjs.Sound.registerSound("sounds/sound_must_be_on.mp3", "soundOn");
$('.btn.sound').click(soundMustBeOn);

onclick listener:

function soundMustBeOn() {
   createjs.Sound.setMute(false);
   createjs.Sound.setVolume(1);
   createjs.Sound.play("soundOn");
}

This works perfect on all modern desktop browsers, iOS and Android 5.x and higher. But on Android 4.4 (on a WebView) it just crashes. What have I missed? I have tried Cordova, Phonegap, SoundJS CordovaAudioPlugin, file:// paths, resources outside the android_asset folder, and plenty of other things. My quess is that I have used Phonegap totally wrong, I could really use a "for dummies" example.

  • Have you tried this https://github.com/floatinghotpot/cordova-plugin-nativeaudio ? I have had success with it in the past for audio. – gro May 16 '15 at 17:03
  • I was thinking maybe to avoid using cordova/phonegap all together since the web app is fully functional as-is on iOS and Android 5.x But I might not have a choise in the matter for Android 4.x and lower. And that sucks, because I need to make some major modifications on something that's already been developed and tested. – Georgios Dimitriadis May 17 '15 at 09:43
  • Older versions of Android used a version of the stock browser for the web view, which has terrible audio support. Sorry it didn't work for you, but glad you found a solution. – OJay May 19 '15 at 15:51

1 Answers1

1

Solved it.

I did what I didn't want to do, but I guess it had to be done. I encapsulated my entire web application within Cordova/Phonegap, downloaded and added the CordovaAudioPlugin.js file from SoundJS and simply registered the plugin as others have already done (also updated the file path)

createjs.Sound.registerPlugins([createjs.CordovaAudioPlugin]);
createjs.Sound.registerSound("/android_asset/www/sounds/sound_must_be_on.mp3", "soundOn");