Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Is it possible to keep an app awake after lockscreen? — Gideros Forum

Is it possible to keep an app awake after lockscreen?

piepie Member
edited October 2013 in General questions
Hi, I am trying to put together a small music player (it should play just some app-embedded music).
My biggest problem is that I have it to keep playing music either when the phone is locked, so that the user can put his phone inside a pocket without worrying about touching the screen (and saving up some battery).
Basically I think I just need to avoid "app-pause" and "app-resume".

I tried searching the forum, but couldn't find anything useful or related to my scenario.
Could someone please share some advice?

thank you very much
P.

Comments

  • @pie currently there is no pure Gideros implementation, but maybe it is possible with some OS specific modifications.
    So which OS would you want to support? IOS, Android, both?
  • piepie Member
    Both would be perfect in the future, but at this time I just need this for android :)
    Thank you
  • ianchiaianchia Member
    edited October 2013
    This is for iOS. I'm just popping it here for future reference for folk searching through the forum with the same query. Apologies - I don't have an Android answer.

    In the AppDelegate.m file, just before the end of:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    insert:
        [UIApplication sharedApplication].idleTimerDisabled = YES; // stop device from sleeping
    So the end of that method looks like:
     
        [self.window makeKeyAndVisible];
     
        [UIApplication sharedApplication].idleTimerDisabled = YES; // stop device from sleeping
     
        return YES;
    }
    I do this all the time for the exported Gideros iOS Player during development because it saves me having to touch the screen every few minutes to avoid device sleep, which gets to be !#(*^&%@# annoying. (-;

    Note this is different to the use-case as specified in the original question. Under iOS, you can't keep the app "awake" after lock screen. However, you can specify certain services to continue after lock screen (such as music.) For such cases, you need to configure your app for the specific service.

    In the case of music, this answer by gabriel_vincent on Stackoverflow works fine:

    http://stackoverflow.com/questions/8926107/continue-audio-playback-when-iphone-is-locked-like-ipod-app

    - Ian
  • @pie you would need to dive into more native development. For android, you would need to create a service, that would get the play list and provide, play, stop, pause and next/prev functions.
    http://stackoverflow.com/questions/16336960/android-playing-music-in-background
    And then create Gideros plugin to communicate with this service

    @ianchia http://docs.giderosmobile.com/reference/gideros/Application/setKeepAwake#Application:setKeepAwake :-\"
  • @ar2rsawseen Thanks! Application:setKeepAwake huh. Never noticed that API … (-;

    - Ian
  • piepie Member
    Thank you both :)

    @ar2sawseen I'm lucky I don't need to pass play/pause ext/prev controls to the app, the app should just "play in loop some embedded WAVs". :) I'm sorry if I wrote the question in the wrong way.

    What I would need is to keep the application running even after locking the screen (as an example take any music player: if I have it playing something and I lock the screen, it still continues playing).

    I already tried application:setKeepAwake, but I'd say it's not doing exactly what I need - unless there is a smarter way to use it than the one I used it ( I just put it at the beginning of main.lua).

    In my test on the android gideros player, " application:setKeepAwake(true)" keeps the application running while the phone is unlocked (it "removes" the screen timeout, and the app is actually still running even with no interactions) but it doesn't keep the app "alive in background" if I manually lock the screen.
    Didn't tried it in a compiled apk, but I suppose it would behave the same.

    I still need to dive into android native development, am I right? :)

    I tried googleing around but I'm not even sure on what to look for... If only I could find something I would give it a try, but I am afraid it would be far out of my comprehension/skills :D

    Thank you!
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @pie no matter the purpose, gideros still pauses its own thread in background and you can only do something in services in native platform and post the result back to lua thread, when app is back to foreground
Sign In or Register to comment.