[Finally solved] CocoonJS on resume bg music bug.

Discussion and feedback on Construct 2

Post » Sat Aug 24, 2013 7:24 pm

Probably you have noticed that when you resume your app wrapped with CocoonJS 1.4 on android the bg music plays twice. I finally found the problem and managed to resolve it.
The new CocoonJS audio engine seems to handle itself the onsuspended and onresume conditions, so I had to remove some code lines in c2runtime.js that also handled the same conditions making the bg music duplicate.

To apply this workaround you have to follow these steps.

1) Export your project without minifying your code.

2) Uncompress c2runtime.js and open it with a text editor (I suggest Notepad++)

3) Find the following lines of code

C2AudioInstance.prototype.setSuspended = function (s)
     {
          
          switch (this.myapi) {
          case API_HTML5:

              if (s)
              {
                    if (this.isPlaying())
                    {
                         this.instanceObject["pause"]();
                         this.resume_me = true;
                    }
                    else
                         this.resume_me = false;
              }
              else
              {
                    if (this.resume_me)
                         this.instanceObject["play"]();
              }
              break;

4) delete everything in the middle of case API_HTML5 and break. It should look like this:

case API_HTML5:
break;

5) Save and put the modded c2runtime.js in your project zipped file

6) Enjoy Knifegrinder2013-08-24 19:25:04
B
11
S
3
Posts: 224
Reputation: 2,028

Post » Sun Aug 25, 2013 3:31 am

@ashley

Any comment on this ?

@knifegrinder

Maybe you can submit a bug report on this issue.
B
79
S
22
G
14
Posts: 389
Reputation: 12,324

Post » Sun Aug 25, 2013 1:50 pm

This will break music on other platforms (e.g. it will continue to play music in the background when switching tab in a browser). It's a CocoonJS bug, you should report it to Ludei.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Sun Aug 25, 2013 4:02 pm

[QUOTE=Ashley] This will break music on other platforms (e.g. it will continue to play music in the background when switching tab in a browser). It's a CocoonJS bug, you should report it to Ludei.[/QUOTE]

True. And this issue has been reported to Ludei by various users on their forum.
That's why I suggested to work on the c2runtime.js created with the cocoonjs exporter instead of editing directly the audio plugin runtime.js.
This way you don't break anything and works as a temporary workaround.
B
11
S
3
Posts: 224
Reputation: 2,028


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 16 guests