androidhtmlcordovaaudiosoundjs

Unable to play sounds on Android Game Build using Cordova


Please can someone help me- this is driving me crazy!!!

I have created a HTML5 project which uses PreloadJS and SoundJS to play some sounds. It works absolutely fine in Chrome but when I push it to Cordova Emulator (Android SDK) or to my Android mobile, it builds and deploys successfully, but I get no sound at all and I can't figure out why. The Android monitor shows the following errors but I am not sure if they relate to SoundJS:

•I/MediaFocusControl(1258): AudioFocus requestAudioFocus() from android.media.AudioManager @ b303c1a8com.android.org.chromium.media.MediaPlayerListener@b30f0238

•E/MediaPlayer(1904): error (1, -2147483648)

I am trying to fire the sound on a button click event so I don't think it is related to a security issue.

I am pre-loading the sound files using the following code:

p.assetsPath = 'assets/';

p.initialize = function () {

   this.EventDispatcher_initialize();

   this.loadManifest = [
      {id:this.MENUSOUNDTRACK, src:this.assetsPath + 'MainTrack.ogg'},
      {id:this.GAMESOUNDTRACK, src:this.assetsPath + 'BackingTrack.ogg'},
 .......
}

p.preloadAssets = function () {
   createjs.Sound.initializeDefaultPlugins();
   createjs.Sound.alternateExtensions = ["mp3"];

   this.queue = new createjs.LoadQueue();
   this.queue.on('progress',this.assetsProgress,this);
   this.queue.on('complete',this.assetsLoaded,this);

   this.queue.installPlugin(createjs.Sound);        
   this.queue.loadManifest(this.loadManifest);
}

All of the sound files are stored in /www/assets which I believe should be automatically mapped to /android_asset/www/assets by cordova.

Any help would be really appreciated.


Solution

  • You can see some discussion around using PhoneGap here which will likely be relevant.

    In theory everything should work with Cordova, but it is not well tested.

    I would suggest making sure all sounds are loaded completely before attempting playback, making sure you are using the latest version of soundjs from github, and testing one of the simple examples from github to confirm if its a SoundJS and Cordova issue or if there is something in your implementation.

    Hope that helps.