applicationSuspend event sent "too late"

I build for iphone or android ,then install it in my devices and appears on the device like popup only the first time you start the game.

Im pretty sure it will appear to my end users too.

If we can remove it everything will be fine!!I will use 971 for android and latest build for iphone!

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

Hi @Odijack,

OK, I checked into this, and with 971 the pop-up will appear for non-subscribers. It should not appear for non-subscribers using 1076.

So basically, it appears that you have 3 choices, if you wish to remain a Starter user:

  1. Release with 1076 and “accept” that the issue will occur on a few Android devices like the “mini 2” if, and only if, the user force-exits the app with the power button (not the “home” button). In the plus column, assume the game will run just fine on most Android devices and all iOS devices.

  2. Use the “media” library. When I said that your sound setup is “simple”, I meant (from your earlier post) that you’re merely playing basic audio tracks and sound effects. Most likely you don’t need to “seek”, “rewind”, or use other OpenAL features. I might be mistaken about what you’re doing with the audio, but the media library does handle essential audio needs just fine: playing, stopping, pausing, adjusting volume, etc.

  3. Wait for the next public release in which this issue might be fixed (Android is often a moving target in this regard because of the countless devices, models, core processors, and OS versions in the market).

It’s not only the sound problem.Power button makes the game unplayable because mess with timers too.There are more problems because of suspend changes.You shouldnt act like i imagine the problems.Someday i will make a post.So no2 is not a solution.No1 is not a solution either.I have no idea how many devices have the same problem.As for no3 no comments. Our only real solution is to pay for pro and use 971 build. We regret using corona but we must find a solution and release the game. Brent and Joshua ty for your time.

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

@Odijack,

I don’t act like you’re imagining the problem, but I think you overestimate the number of devices that it potentially occurs on. If this was a widespread issue on Android, we would have received several reports from several users and fixed it in 1076… but that did not happen. So, I maintain this is an isolated case.

That being said, I don’t treat it as “unimportant” just because it’s isolated. We want to support as many Android devices as possible, but there are thousands of them. If you submit a proper bug report, we can investigate this further and try to fix it in a daily build upcoming, but since you’re a Starter user, you would not be able to use that build. Suggestion #3 should warrant some consideration for you, however, as the next public build is not that far away. If you submit a proper bug report, then we can investigate this sooner than later and hopefully get it fixed… but if you must release the game next week, then this isn’t an option.

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.

I dont want to make another topic , so i will post here.

I thought a few solutions but didn’t work except one!

I abandoned landscape and used only portrait in build.settings.Then i rotated the display groups 90 degrees and repositioned a few images-buttons.This way i use portrait but player must hold horizontal the device like landscape :slight_smile:

Everything works great now!

I wonder if there is any problem with this method…

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]