SoundJS 0.5.2 Audio Plugin for CocoonJS 1.4.7

I just updated the CocoonJSAudioPlugin.js to work with SoundJS 0.5.2 and CocoonJS 1.4.7

Download: CocoonJSAudioPlugin

How to use: Just put the CocoonPlugin as the first entry to register and you can use everything else of the SoundJS-library just as is in CocoonJS now.

Playing the same sound multiple times parallel/overlapping: You will have to set the maximum number of parallel sounds in the register-method:

  • Pingback: CocoonJS AudioPlugin for SoundJS | indiegamr

  • lgmn

    I have a few questions about the plugin as i’m having a few problems getting it to work.

    – Does the plugin work with PreloadJS or do I have to use Sound.registerSound()?
    – I’m getting an error saying ‘GOT NO TAG’ and ‘Begin Playing: undefined’ even though the source is correct.

    Any help would be much appreciated!

    • olsn

      Sorry, I haven’t tested it with PreloadJS yet – since that should not be needed with CocoonJS :)
      Do you get the same issues when you use Sound.registerSound()?

  • lgmn

    It looks like its working fine when using Sound.registerSound().
    We are using PreloadJS still just because its convenient and these games we are working on have to run as browser based HTML5 games as well.

    We are trying to minimise the amount of code differences there are between a standard HTML5 app and a CocoonJS ready one.

    What would be your recommendation on the subject?
    And if you could explain that plugin in detail I would greatly appreciate it!

    • olsn

      I’ll have to dig into PreloadJS to see how sounds are loaded there.
      Essentially the plugin is pretty much the same as the HTMLAudioPlugin (that was the code-base) but with some changes to make it work with the CocoonJS-api.
      For example, you have to call tag.src = ‘mysound.ogg'; and then call tag.load(); … for regular HTML just setting the src will be enough. Or removing the stalling-event, which is not available on CocoonJS and stuff like that.
      And what it also does, it preloads every registered sound(unlike the HTMLPlugin, which preloads only 1 instance), so my guess right now is, that if you use PreloadJS, the sound won’t be pre-initialized and therefore no tag is found on .play().

  • lgmn

    Thanks a lot for the explanation mate!

  • OJay

    Hi I work on SoundJS and this is awesome to see. Nice work.

    To answer the above, you can install SoundJS as a plugin for PreloadJS, which causes PreloadJS to use SoundJS to load sound. My best guess as to why this CacoonJSAudioPlugin isn’t working with it would be that it isn’t returning a loader. If you look at the WebAudioPlugin, you can see an example of building out a loader that is used both internally and by PreloadJS.

    Hope that helps.

    • olsn

      Awesome, thanks for the hint, I’ll take a look at that when I find some time.

      • Rodrigo


        Great Post!

        I have 2 questions, did you test it on cocoonjs 1.4.7 on ios and if yes it worked fine ? What audio format did you used?


  • Alex

    Thanks for awesome plugin ! Is there a Github repository for it? It would make following it easier.

    I have a small issue – volume control does not seem to work.“background”, { volume: 0}) mutes the sound in the browser, but have no effect in Cocoon

  • Alex

    Ok, I’ve found the problem and fixed it (lines 413-428)

  • Alex
    • olsn

      Nice! Good work!
      I’m super swamped currently and will not be able to work on this regularly. I’ll make a github repo if I find time, otherwise feel free to make one yourself, I’ll link it here.

  • Alex
  • Richie

    Hey olsn, Thanks for the plugin. I am trying to use your 0.5.2 plugin with SoundJS 0.5.2 and also CocoonJS 2.1.1. Should it be compatible with this? I am trying to use in CocoonJS Launcher on my iPad (iOS 8.1.2) and it gives me the following errors:

    Audio load error ”: Could not find audio file named: “www/assets/sounds/highScore.ogg”
    … the same for the rest of the audio files that I have…
    I reference the audio files in a relative manner via PreloadJS with no reference at all to ‘www':

    this.loadManifest = [
    {id:”HIGH_SCORE”, src:this.soundsPath + ‘highScore.ogg’}
    createjs.Sound.registerPlugins([createjs.CocoonJSAudioPlugin, createjs.WebAudioPlugin, createjs.HTMLAudioPlugin]);
    this.queue = new createjs.LoadQueue();
    createjs.Sound.alternateExtensions = [“mp3″];

    sorry for all the code snippets, but it is hopefully easier to see what it is that I am doing. Other file types (JS, images, etc…) seem to load fine, it’s just the sound that is having issues. Is this something that you might be able to assist me with? Thanks