How do I C2 Audio Plugin does not consume a lot of energy

Get help using Construct 2

Post » Sun Mar 05, 2017 2:47 pm

Hello, I need help in creating or modifying the Scirra Audio plugin so that it does not consume a lot of energy on devices like smart watches during the application is suspended.
During time pause audio plugin application consumes more energy - I have no doubt (it's a long story)
How to do it?
What is fix in this plugin ( runtime.js)?
May be this is piece of code ( Audio Plugin - runtime.js)

Code: Select all
C2AudioInstance.prototype.setSuspended = function (s)
   {
      switch (this.myapi) {
      case API_HTML5:
         if (s)
         {
            // Pause if playing
            if (this.isPlaying())
            {
               this.resume_me = true;
               this.instanceObject["suspend"]();
            }
            else
               this.resume_me = false;
         }
         else
         {
            if (this.resume_me)
            {
               this.instanceObject["play"]();
               this.resume_me = false;
            }
         }
         
         break;

Unloading all - does not help.
I understand that the audio plugin pauses during the suspension, and it is necessary to stop it.
What can you advise?
Thank you in advance

@Ashley
B
16
S
4
G
1
Posts: 60
Reputation: 1,131

Post » Mon Mar 06, 2017 10:57 am

The Audio plugin is already designed to suspend the audio context when the app goes in to the background - specifically to save power.

However if you enable the "Play in background" property it won't, so make sure that's disabled.
Scirra Founder
B
395
S
232
G
88
Posts: 24,375
Reputation: 193,790

Post » Mon Mar 06, 2017 7:05 pm

@Ashley

"Play in background" always No

Now i'm ill

tomorrow with video and logs I hope I will tell you and post here why I decided that the matter in the audio plugin...

this is top and tema is not closed
B
16
S
4
G
1
Posts: 60
Reputation: 1,131

Post » Tue Mar 07, 2017 9:16 pm

@Ashley

I'm make the web app for wearable devices that needs to save energy while pausing - it's not just a hidden state or background but also a screen state off (pause).
The app with sounds and music (both folders).
It's not the first year that I've been refused acceptance of such apps because of the energy excess during the pause (the screen state off), although other applications without music and sounds have never had such a reason and problems.

And also, I certainly add this into code file index.

Code: Select all
// 2Pause and resume on page becoming visible/invisible
      function onVisibilityChanged(previousState, changedState) {
         console.log("Screen state changed from " + previousState + " to " + changedState);
         if (document.hidden || document.mozHidden || document.webkitHidden || document.msHidden || changedState=="SCREEN_OFF")
            cr_setSuspended(true);
         else
            cr_setSuspended(false);
      };
      
      document.addEventListener("visibilitychange", onVisibilityChanged, false);
      document.addEventListener("mozvisibilitychange", onVisibilityChanged, false);
      document.addEventListener("webkitvisibilitychange", onVisibilityChanged, false);
      document.addEventListener("msvisibilitychange", onVisibilityChanged, false);

       // Sets the screen state change listener.
       tizen.power.setScreenStateChangeListener( onVisibilityChanged);



Console is shown when screen is off – Suspend always on. Conversely – screen on – app resume



And while the screen is off - everything is suspended -

Since I do not have a tool to measure virtually the energy, etc. during the app pause, I asked one kind guy (he has the opportunity and knowledge) to see what is happening with app during the pause.
Here is his answer.

“I have found the problem that causes your app HIGH current.

Sound and music should be paused when your app is paused
because the api for sound/music will work even if your app is in background.

Actually I don’t know what api to pause sound/music but you would know that.”


Next, I tried to Unload all the audio during the suspend time. It did not help.


At C2 editor after suspended events :

"Play in background" always No
Index file with suspend behavior - see first code above


Anyway -Current consumption is too high on sleep mode.

Standards are
Min current: 33.6 mA, Average current: 42.712 mA
- Samsung Gear S3 standard current consumption
Average current: 10 mA




Video is not very good in quality.

Test start time – start 17-25

Time when the screen is off (pause) 17-27 -36



Sound and Audio somehow works after suspend



I'm sure it's an audio plugin. I need to understand what can be done with this, because I like music applications, I work with music too.
Last edited by shukra on Wed Apr 05, 2017 6:08 am, edited 2 times in total.
B
16
S
4
G
1
Posts: 60
Reputation: 1,131

Post » Wed Mar 08, 2017 11:06 am

Construct 2's Audio plugin specifically suspends and resumes the audio context to save battery life, and it looks like the suspend and resume events are firing correctly.

I'm not sure what kind of browser comes on the Samsung Gear S3, but maybe it doesn't support suspending the audio context? If you check in the browser console on the device if AudioContext.prototype.suspend is available, that would identify the issue. If the browser doesn't support suspending or resuming the audio context, the problem is with the browser, not C2 - C2 will use these to optimise battery life if they are available, but if they're not available there's not much choice other than to leave the context running idle in the background.
Scirra Founder
B
395
S
232
G
88
Posts: 24,375
Reputation: 193,790

Post » Wed Mar 08, 2017 1:36 pm

@Ashley

Ashley wrote:. If the browser doesn't support suspending or resuming the audio context, the problem is with the browser, not C2 - C2 will use these to optimise battery life if they are available, but if they're not available there's not much choice other than to leave the context running idle in the background.

I will ask on tizen forum about browser and supporting Audio suspend.

But I must add - that when suspend work - sound or music doesn't work
when Resume - then it works again.

I chek my music app in Emulator for GearS2 S3 ... and logs shown that Media suspend works....
That time the music file is playing ( folder Music)

Image

I need add this about tizen browser - I have NO such problem with another Tizen device ( Geas S, Mobile Tizen Z devices).
So... It is pitty, but i must use background mode..
Last edited by shukra on Wed Mar 08, 2017 2:05 pm, edited 3 times in total.
B
16
S
4
G
1
Posts: 60
Reputation: 1,131

Post » Wed Mar 08, 2017 1:49 pm

When it suspends it has to stop playing audio otherwise the audio processing is still working, which is exactly what uses power.
Scirra Founder
B
395
S
232
G
88
Posts: 24,375
Reputation: 193,790

Post » Wed Mar 08, 2017 2:09 pm

@Ashley
Ashley wrote:When it suspends it has to stop playing audio otherwise the audio processing is still working, which is exactly what uses power.

Of course I understand this. I thought so.
But the results and many attempts make me think that the Audio plug-in stops the sound, but somehow and for some reason it will consume energy.
B
16
S
4
G
1
Posts: 60
Reputation: 1,131


Post » Sun Mar 12, 2017 11:06 am

Ashley wrote:If you check in the browser console on the device if AudioContext.prototype.suspend is available, that would identify the issue.

Have you checked this yet? This is the most important thing to check.
Scirra Founder
B
395
S
232
G
88
Posts: 24,375
Reputation: 193,790

Next

Return to How do I....?

Who is online

Users browsing this forum: blackhornet, Bootfit, Exabot [Bot], Huemerson, unicornspitfire, Yahoo [Bot] and 1 guest