1

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.

user3805377
  • 27
  • 1
  • 8

1 Answers1

0

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.

OJay
  • 1,249
  • 7
  • 14
  • Hi Ojay, Thanks for you message. i have stumbled across that link when trying to find a fix, but it concludes that they couldn't get it to work, so used another library. I was hoping that some one would say they definitely had soundjs working and how they did it... (And then I can work out why my code is off the mark) – user3805377 Jul 05 '14 at 09:08
  • They note early on that the [mobile safe approach](http://www.createjs.com/tutorials/Mobile%20Safe%20Approach/) does work in phonegap. [Work](https://github.com/CreateJS/SoundJS/pull/37) has been done to help SoundJS work with phonegap, but its not something we test against. – OJay Jul 07 '14 at 16:48
  • Hi OJay - whatever I try, I can't get SoundJs working with Cordova and Android. So frustrating as I love CreateJS and EaselJS. – user3805377 Jul 17 '14 at 16:38
  • Sorry to hear that. We've considered added a plugin for Cordova/PhoneGap but its not something we've had time to implement. I keep hoping someone in the community will put one together and add a pull request to the repo. – OJay Jul 18 '14 at 15:44