applicationSuspend event sent "too late"

When leaving the app via the “power” button of my Samsung Galaxy Device (NOT the HOME-button), the background music keeps playing until I re-open the app.

I print the “type” of the SystemEvent as soon as it occurs, and I have noticed the following:
When pressing the power button (and thus sending the phone to stand-by), no system event occurs.
After leaving standby and re-opening the app, I can see the “applicationSuspend” AND “applicationResume” event happening shortly after each other.
So the “suspend” is triggered when RE-activating the app, not when actually “suspending” it.

Has anybody else witnessed this problem? [import]uid: 24497 topic_id: 37485 reply_id: 67485[/import]

I have the same problem.

Did you find any solution?

Hello,

The “applicationSuspend” event is not available on/before a forced termination, because it immediately halts the Runtime and there is no opportunity to read the event that was sent to the system until you restart the app. This is why, on resume, you’re seeing both the “suspend” event (queued from when the app was suspended) AND the “resume” event.

Brent

So, how do we stop music if power button is pressed?

Hi @matthias3,

Audio is supposed to stop playing when you press either the “home” button OR the power button. Can you give me the exact device you’re testing on where the audio continues to play? And what build of Corona you used in this test? Are you using the “media” library methods or the “audio” library methods?

@Odijack, which device are you using?

This might be a bug, but I need more info to determine so…

Thanks,

Brent

build 2013.1076

device 1: samsung galaxy s i9000 (2.2 os version)

device 2: samsung galaxy mini 2 (2.3.6 os version)

I use audio library and mp3 files.

ok , it’s build.settings

when i use this, sound doesnt stop:

settings =

{

        orientation =

        {

                default = “landscapeRight”

                

        },

}

but when i use this everything is ok with sound:

settings =

{

        orientation =

        {

                default = “landscapeRight”,

                supported =

                {

                        “landscapeLeft”, “landscapeRight”, “portrait”, “portraitUpsideDown”,

                },

        },

}

I really need an answer.It’s crazy…

I downloaded 2012.971 (previous version) and everything works fine.The sound and transitions both.(yes i had transitions problem too)

It happens every time you set landscape instead of portrait in build.settings and press power button ingame.

It’s a huge problem and i cant publish my (almost completed) game :confused:

Hi @Odijack,

This is just purely whacky. :slight_smile: In your first example above, where you’ve omitted the “supported” table entirely, can you add that back in with just the landscape strings? I just want to see what happens… and of course, I image you’d want to have both landscape directions available to the user…

What were the transition problems you were having? That shouldn’t have been anything that changed between 971 and 1076, but if you give me an example, I might be able to help.

Brent

Ok lets forget transitions.I do many things at the same time and maybe transitions have nothing to do with build.settings

I make a simple main.lua playing an mp3 file.Without build.settings it goes portrait and when i press power button music stops.

Then i add build.settings with both left and right landscape (doesnt matter , just dont add portrait) and when i press power button the sound doesnt stop!

In two devices.

I can sent you zip files to check for yourself :smiley:

Btw thank you for your time

Hi @Odijack,

Out of curiosity, can you try using the “media” library functions to play the same music? While these don’t have the same level of “control” as the audio library ones, sometimes they’re more friendly with Android devices. Mostly I want to just see what happens. :slight_smile:

If it’s music that you’re playing (not just a sound effect), then “media.playSound” is the one to test:

http://docs.coronalabs.com/api/library/media/playSound.html

Brent

Ty Brent!

Its ok now.I have never used media library.I hope i can control audio like before.I have background music and a few sound effects.

Ty again :smiley:

On iphone i call my pause function in applicationSuspend/Resume and works just fine.

With the same code nothing happens in android…

Any advice?

Can you post the function code and how you’re triggering it?

local function onSystemEvent2( event )

        if event.type == “applicationSuspend” then

            audio.pause({channel=1})

            pausegame( )

        elseif event.type == “applicationResume” then

             --pausegame( )

             --audio.pause({channel=1})

        end

    end

    Runtime:addEventListener( “system”, onSystemEvent2)

Even if i uncomment on resume too i cant stop audio or pause game in android.

On iphone works perfect with both home button and power button.

To be clear , nothing happens only if i press power button.

With home button game pause and sound stop like it should.

Hi @Odijack,

As I mentioned in the post near the top, you won’t get the “applicationSuspend” event on/before a forced termination, because it immediately halts the Runtime and there is no opportunity to read the event that was sent to the system until you restart the app.

Also, can you test out this pause function? It uses a “gamePaused” flag, which is just a boolean that you set in the beginning (to false, obviously). Notice how on the “resume” event, it doesn’t actually try to resume the game itself. Instead, it assumes that (on pause) you’ll be bringing up some kind of pause menu with a button to resume the game. So, on resume, the app continues in the paused state… you game’s paused state, not internally paused by the OS… and then you click the button to resume, in a tap listener that calls the “pausegame()” function. In that function, I handle both the pause and un-pause functionality, based on the “gamePaused” flag state, swapping it between true/false depending on the starting condition.

[lua]

local function devicePause( event )

   if ( “applicationSuspend” == event.type ) then

      audio.pause( 0 )

      if ( gamePaused == false ) then

         pausegame()

      else

         print(“NO RE-PAUSE (FROM DEVICE SUSPEND)”)

      end

   elseif ( “applicationResume” == event.type ) then

      audio.resume( 0 )

   end

end

Runtime:addEventListener( “system”, devicePause )

[/lua]

I did this but… same problem.

Home button pressed then game paused when i restart the game

Power button pressed game not paused when i restart the game

I even removed pausedgame ( ) and tried something simpler but did nothing.

Placed a button in the middle of the screen.

somebutton.isVisible=false

if event.type == “applicationSuspend” then

           somebutton.isVisible = true

It looks like applicationSuspend event is not available before a forced termination and still not available on restart!

Hi @Odijack,

Is this happening on iOS or Android? Also, do you still have (or can you get) Build 971… the previous public build… and test on that as well? I think some very minor handling of the system events occurred around Build 1052-1053, so I’d like to see if anything varies between 971 and 1076.

Brent

Just used Build 971 and works fine.

Btw media library is a mess compared to audio library.Check the orientation - audio - power button bug too.(Works fine in Build 971 too)

Who could release a game with these 2 problems?

Can i get Build 971 without forced watermark/splash screen? :smiley: