Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
How to make app continue running after turning off phone screen? - Gideros Forum

How to make app continue running after turning off phone screen?

Apollo14Apollo14 Member
edited October 10 in General questions
Hi guys!

I need app to continue playing when user turns screen off.
Can we do it somehow in Gideros?


(Currently when user turns screen off, Event.APPLICATION_SUSPEND triggers
and Event.APPLICATION_RESUME after turning screen on)

Can we ignore that Event.APPLICATION_SUSPEND and make app run there normally like nothing happened?

Many thanks!
> Newcomers roadmap: from where to start learning Gideros
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)

Comments

  • hgy29hgy29 Maintainer
    Accepted Answer
    Basically you can’t. What you are trying to do is called background activity, and phones typically forbid that, except for very specific use cases.

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • olegoleg Member
    edited October 10
    Apollo14 said:

    Hi guys!

    I need app to continue playing when user turns screen off.
    Can we do it somehow in Gideros?


    (Currently when user turns screen off, Event.APPLICATION_SUSPEND triggers
    and Event.APPLICATION_RESUME after turning screen on)

    Can we ignore that Event.APPLICATION_SUSPEND and make app run there normally like nothing happened?

    Many thanks!

    я так робив з APPLICATION_SUSPEND це працює -просто зберігаєш гру при вимкненні а потім при увімкненні вираховуєш час і зміни за цей час у грі, також є інший варіант використати Application:setKeepAwake -і самому затемняти екран імітуючи виключення дисплею..
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • thx guys, got it, I guess for such purposes I would have to learn freaking Android Studio
    (but I guess I'll skip learning freaking Android Studio for now, I already have enough adventures in my life)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • @Apollo14 I'll try to have a look at this in android studio when I have time and will come back!

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited October 13
    Hey guys! @hgy29 @MoKaLux
    I've found description of my intentions: https://stackoverflow.com/questions/39080815/continue-playing-the-music-when-screen-goes-off
    (actually I need just mp3 to continue playing)

    People on stackoverflow say that event ".onPause" triggers.
    Does Gideros also react to that ".onPause" event? Can it be ignored somehow?

    p.s. I'm looking at audio-related files https://github.com/gideros/gideros/blob/master/libgid/src/gaudio.cpp
    and https://github.com/gideros/gideros/blob/master/libgid/src/android/gaudio-background-mediaplayer.cpp
    but still have no idea what could possibly be done

    Many thanks!
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • MoKaLuxMoKaLux Member
    edited October 13
    @Apollo14 short answer is: not possible right now.
    Long answer: from the github source code it seems that the sound (music) is paused when your app is paused (screen off, put in background, ...)
    It seems to be this code for android:
    https://github.com/gideros/gideros/blob/master/android/GiderosAndroidPlayer/app/src/main/java/com/giderosmobile/android/player/GGMediaPlayerManager.java
    public synchronized void onPause()	{
    	if (suspended_)
    		return;
    	for (int i = 0; i < channels_.size(); ++i)
    	{
    		Channel channel = channels_.valueAt(i);
     
    		if (channel.player == null)
    			continue;
     
    		if (channel.player.isPlaying())
    		{
    			channel.player.pause();
    			channel.suspended = true;
    		}
    	}	
    	suspended_ = true;
    }
    This code is called in the GiderosApplication.java file.
    Unfortunately you cannot modify this file yourself because it is precompiled inside gideros.aar file in the template (see: http://forum.giderosmobile.com/discussion/7802/media-plugin)

    PS: I am watching the video to see the best way to use media in android (from your so question you posted above). done!
    PS2: there seems to be much more to this (putting controls on the home screen, ...) https://github.com/android/uamp

    Likes: Apollo14

    +1 -1 (+1 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited October 14
    MoKaLux said:


    It seems to be this code for android:
    https://github.com/gideros/gideros/blob/master/android/GiderosAndroidPlayer/app/src/main/java/com/giderosmobile/android/player/GGMediaPlayerManager.java
    Unfortunately you cannot modify this file yourself because it is precompiled inside gideros.aar file in the template

    Wow THX! That's really helpful!
    So after commenting out this piece of code in GGMediaPlayerManager.java and recompiling gideros.aar, audio will continue playing after screen is turned off?
    public synchronized void onPause()	{
    	if (suspended_)
    		return;
    	for (int i = 0; i < channels_.size(); ++i)
    	{
    		Channel channel = channels_.valueAt(i);
     
    		if (channel.player == null)
    			continue;
     
    		--if (channel.player.isPlaying())
    		--{
    		--	channel.player.pause();
    		--	channel.suspended = true;
    		--}
    	}
    	suspended_ = true;
    }
     
    public synchronized void onResume()
    	{
    		if (!suspended_)
    			return;		
     
    		for (int i = 0; i < channels_.size(); ++i)
    		{
    			Channel channel = channels_.valueAt(i);
     
    			if (channel.player == null)
    				continue;
     
    			--if (channel.suspended)
    			--{
    			--	channel.player.start();
    			--	channel.suspended = false;
    			--}
    		}	
     
    		suspended_ = false;
    	}
    If so, I can temporarily replace my original gideros.aar with custom gideros.aar and build my android app? (then switch back to original file for other projects)

    How to recompile gideros.aar? In can be done in QT?
    @hgy29 would you be so kind to recompile this file? (if it's all set on your machine, I've never worked with QT, not sure how it's all done there)
    MANY THANKS guys!
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • hgy29hgy29 Maintainer
    You don't need QT, just android studio for that part, but anyway I can do it for you to try
  • Apollo14Apollo14 Member
    edited October 14
    hgy29 said:

    You don't need QT, just android studio for that part, but anyway I can do it for you to try

    That would be great! <3
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • hgy29hgy29 Maintainer
    Accepted Answer
    Here it is (zipped)

    Likes: talis

    zip
    zip
    gideros.zip
    65K
    +1 -1 (+1 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited October 16
    hgy29 said:

    Here it is (zipped)

    Hey guys!! I've just managed to compile couple of apks with and without modified 'gideros.aar' file.
    It works like a charm now! Audio is playing when screen is off.
    @MoKaLux @hgy29 Thanks a lot guys!!

    Likes: MoKaLux, talis, antix

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+3 / -0 ) Share on Facebook
Sign In or Register to comment.