Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

applicationSuspend event sent "too late"
Started by matthias3 Mar 11 2013 06:31 AM

65 replies to this topic
[TOPIC CONTROLS]
Page 1 of 3 1 2 3
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

matthias3

[GLOBAL: userInfoPane.html]
matthias3
  • Observer

  • 11 posts
  • Corona SDK

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?
uid: 24497 topic_id: 37485 reply_id: 67485


[TOPIC: post.html]
#2

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

I have the same problem.

 

Did you find any solution?



[TOPIC: post.html]
#3

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

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



[TOPIC: post.html]
#4

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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

[TOPIC: post.html]
#5

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

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



[TOPIC: post.html]
#6

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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.



[TOPIC: post.html]
#7

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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



[TOPIC: post.html]
#8

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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 :/



[TOPIC: post.html]
#9

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

Hi @Odijack,

This is just purely whacky. :) 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



[TOPIC: post.html]
#10

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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 :D

 

Btw thank you for your time



[TOPIC: post.html]
#11

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

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

 

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



[TOPIC: post.html]
#12

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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 :D



[TOPIC: post.html]
#13

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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

 

With the same code nothing happens in android...

 

Any advice?



[TOPIC: post.html]
#14

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

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



[TOPIC: post.html]
#15

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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.


[TOPIC: post.html]
#16

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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

 

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



[TOPIC: post.html]
#17

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

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.

 

 
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 )


[TOPIC: post.html]
#18

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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!


[TOPIC: post.html]
#19

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Moderator

  • 8,346 posts
  • Corona Staff

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



[TOPIC: post.html]
#20

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

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? :D



[TOPIC: post.html]
#21

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Odijack,

 

I can't reproduce this issue either.  That said, I don't have the same devices you have to test with.  The closest equivalent that I have is a Samsung Galaxy SII, model GT-I9100 and OS version 2.3... but I've tested this with several other devices as well.

 

I tested with sample app "Media/AudioPlayer" that is included with the Corona SDK.  That sample app uses the audio library.  Pressing the power button off does indeed stop audio playback for me... and audio resumes when clearing the screen lock on the Android device.  I've also tried setting up the app as landscape just like you, but it still disabled audio correctly when pressing the power button.

 

Can you try testing with that sample app as well please?

When running the app, tap the "Loop" button and then the "Play" button to make it play audio continuously.

The point of this test is to isolate the root cause of this issue.  To see if it is device specific... or if there is something in your code that is somehow triggering this behavior.  Once we're able to reproduce this issue on our end, then we can do something about it or possibly recommend a work-around if possible.



[TOPIC: post.html]
#22

neil.maron

[GLOBAL: userInfoPane.html]
neil.maron
  • Observer

  • 1 posts
  • Corona SDK

Brent, thanks for clarification on applicationSuspend not getting to app. I've been debugging a problem and see I've got to be more proactive about saving the game state so a power off doesn't kill the progress made so far.



[TOPIC: post.html]
#23

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

Joshua,

 

the sample you tested is portait oriented.The issue i described occurs in landscape!I have explained it in previous post.

 

Guys you are driving me crazy...



[TOPIC: post.html]
#24

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Odijack,

 

Yes, I know your app is landscape.  If you see my above post, I've already tried testing with a landscape app too and was still unable to reproduce it.  Can you try the tests in my above post please?

 

I understand these things can be frustrating and we honestly want to help out, but we can't help until you help us isolate and reproduce the issue.  Odds are there is something more to this.  There are a lot of Corona made apps that are landscape-only out there, and if it was as simple as that, then we would have received a lot of feedback about this.  But so far it's just you guys, which tells me that there may be something else about how your app is set up that is triggering this behavior.



[TOPIC: post.html]
#25

PewPewNinjaXx

[GLOBAL: userInfoPane.html]
PewPewNinjaXx
  • Enthusiast

  • 50 posts
  • Corona SDK

Joshua and Brent

 

I appreciate your help and "driving me crazy" statement wasnt appropriate :)

 

Its really frustrating because with build 971 the same code works flawless.

 

I will try the tests.




[topic_controls]
Page 1 of 3 1 2 3
 
[/topic_controls]