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

0 favourites
  • 13 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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)

    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;[/code:22gpri46]
     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

  • 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.

  • 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

  • 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.

    // 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);
    
    [/code:1wgs9fb9]
    
    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]“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.”[/i]
    
    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 [b]No[/b]
     Index file with suspend behavior - see  first code above
    
    Anyway -Current consumption is too high on sleep mode.
    
    [b]Standards are
    Min current: 33.6 mA, Average current: 42.712 mA
    [ul]
    	[li]Samsung Gear S3 standard current consumption[/li]
    [/ul]Average current: 10 mA[/b]
    
    Video is not very good in quality.
    
    [b]Test start time – start 17-25[/b]
    
    [b]Time when the screen is off (pause) 17-27 -36[/b]
    
    [b]
    Sound and Audio somehow works after suspend[/b]
    
    I'm sure it's an audio plugin. [b]I need to understand what can be done with this[/b], because I like music applications, I work with music too.
  • 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.

  • Ashley

    . 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)

    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..

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

  • Ashley

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • maybe its consuming energy to check if audio is still suspended? so basically is the app that consumes energy? and not the audio plugin?

  • > 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.

    Yes, you are right AudioContext.prototype.suspend is not available.

  • Exactly what I thought Those APIs need to be available for Construct 2's battery saving features to work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)