Oppo R9 turns off the power and still plays the sound

Enterprise version: 3086

Mobile phone model: Oppo R9

System version: ColorOS V3.0.0

Android version: 5.1

Problem description: the game works normally, after pressing the power button, the screen is closed, the game’s sound is still in, the game is not suspended. Using the Runtime:addEventListener("system "), there is no suspend event. How can I solve this problem?

i hope somebody can help me ~~

pls

top top

Hi,

Try below bock:

[lua]

local function onSystemEvent( event )    

    local eventType = event.type

    if ( eventType == “applicationExit” or eventType == “applicationSuspend”) then

     audio.stop()

  end

end

Runtime:addEventListener( “system”, onSystemEvent )

[/lua]

-Assif

I tried, but after I closed the screen, the code didn’t come in.

Please do not expect an immediate response to posts and don’t bump your post for at least a day. Please see our Forum Rules:

https://coronalabs.com/forum-rules/

In particular, rules 6 and 13.

Now as for your problem, it’s likely something with the hardware. I’ve never seen an app not get a system event. It sounds like your device isn’t really powering down. If you can’t get that suspend event, you have no way of reacting to the device sleeping.  You should not have to do anything to stop the audio. If your device is behaving correctly the audio should stop on its own. I would go through the device settings and make sure that sleeping the device is really doing that.

Rob

This is my main Activity, which inherits the CoronaActivity, mainly to see if the onPause event is executed. As a result, my logs are output. Note that the onPause is executed, but the sound does not stop.

package com.ansca.corona; import android.util.Log; public class MainActivity extends CoronaActivity { @Override protected void onPause() { super.onPause(); Log.i("TagTag","==============="); } }

This is in my Corona code, which is used to play music, but when I press the power button on my phone, the screen is off, and Java walks the onPause event, but the event of the Runtime is not triggered.

local data = audio.loadStream("feastBGM.mp3") audio.play(data) json = require("json") Runtime:addEventListener("system",function( event ) print("==========================================================================================") print("==========================================================================================") print(json.encode(event)) end)

I hope you can understand what I mean. All my English information is from machine translation. I hope it won’t cause too much misunderstanding.

Hi,
I test the below same sample code on device [oppo 1201] & it is working perfectly.

-When u put the app in suspend via pressing the home key 

-When u press the lock/power key i.e when device get lock

[lua]

local backgroundMusic = audio.loadStream( “test.mp3” )

local backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1, fadein=5000 } )

local function onSystemEvent( event )

local eventType = event.type

if ( eventType == “applicationExit” or eventType == “applicationSuspend”) then

audio.stop()

end

end

Runtime:addEventListener( “system”, onSystemEvent )

[/lua]

Note: I am not using Enterprise Corona

-Assif

Thank you for your reply, but according to my tests, after pressing the power button, Corona did not return the system event…

I’ll ask Engineering to look into this.

Is there a reason you’re still using 3068?  The current public build is 3184 and 3068 is two public builds behind.

It might be worth updating because we fixed an issue that Google Play was flagging.

@assif_tiger, he’s doing native (Formerly Enterprise) builds. There could be something related and it could still be a hardware/OS related issue.

Rob

If I add the following code in the activity’s onPause event, I can make the sound stop, but in the actual test, someone will flash back…

 L.getGlobal("audio"); L.getField(-1,"stop"); L.call(0,0);

@Rob, Thanks you might be correct :slight_smile:

And Appreciate the way you respond still, as of corona & staff are on holidays.

Assif

Google Play was flagging???Will this cause the game to be removed?

In the case of sound, I hope to find a good way to solve the problem.

Yes, Google Play had found a security issue that impacts all existing Corona apps (and others too) and apps need to simply be rebuilt and resubmitted to Google Play with 3184.  Here is the text from the release post with more information:

Google’s ContentProvider path traversal vulnerability warning

This public build also contains an update that addresses Corona made apps that get flagged in Google Play with the “ ContentProvider path traversal vulnerability ” warning. If you’re getting this warning in Google Play, simply rebuild with this version of Corona.

Rob

Thank you. For the power shutdown, can the sound still play be resolved? Or what kind of information do you need to find me?

I have no idea. I asked engineering, but with it being the holidays I don’t know when someone can look at the post.  What might be best is to go ahead and submit a bug report. We need a small demo project that shows the failure that our engineers can build and run on a device and see the problem. With this being a native project, we will need all of the files needed to build it with Android Studio.  Please put it in a .zip file and use the Report a Bug link at the top of the page.

Rob

the issue is related to anonymous listener function, just replace this code 

Runtime:addEventListener(“system”,function( event ) print(json.encode(event)) end)

on 

local function onSystemEvent( event ) print(json.encode(event)) end

Runtime:addEventListener( “system”, onSystemEvent )

try to uninstall and install the app again?