How to stop playing sound, if home button is pressed?

I have a little problem with background music in my app created in app inventor 2.
When screen1 initialize, start a sound in loop mode.
When user tap “home” button and minimize app, the sound still play and only k!ll!ng the app stops sound.
How can I intercept the “home pressed” event for stop/pause sound?
Sorry for my english.

We can’t - Google doesn’t seem to want us to. We can detect if the “Back” button was tapped:


So you will need to time-out the loop.

Thanks for reply.
Timeout the loop?
I can’t know when user will park my app… :frowning:
Can you explain your idea about timeout?
Any other trick or work around?

If you are using the Player Component just enable "PlayOnlyInForeground", it will pause the audio when the app is no longer in the foreground:

1 Like

Yes, but that will also stop the sound if the screen is switched off (standby, sleep mode).
Is it really wanted? Many set the timeout to 10 or 20 seconds, so you have to use this:grafik

Thanks for reply.

YES! This solve my problem...

Very interesting! Thank you for noticed to me!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.