executing action when Chrome goes to background

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

executing action when Chrome goes to background

Post by tsolignani » 22 Jan 2020 16:34

Good afternoon.

When I am playing a video o something in Chrome and hit "home" to use other apps the video pauses and I have to reach the notification and touch play.

Is there a way to execute a flow when an app goes to background, in my case Chrome, and make it restart playing?

Thank you.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: executing action when Chrome goes to background

Post by Desmanto » 23 Jan 2020 18:21

You can use trigger App Task Ended, put Chrome. Then use action perfom click the button at the notification to play again after being paused. This method should work with any app that provide the button in the notification bar.

But special case for chrome, it support media session. We can detect the media session changed, and then send back the command to play it again after being paused. I have made the flow for it. Chrome Continue Audio Background
Chrome Continue Audo SS.png
Chrome Continue Audo SS.png (57.49 KiB) Viewed 6839 times
- The flow has 2 triggers : Media Session Change by Chrome and another shortcut to play/pause. Add the shortcut to home screen.
- Flow continue to separate the trigger. If it comes from media session change by chrome, then continue to check if chrome is running.
- If Chrome is not running, then the media session changed must have been triggered by pressing home, hence Chrome not running and paused the video.
- False (chrome is not running), send back command to play again to the Chrome.
- Show notif that Playback continue
- Sleep for 1 seconds, this is to protect the flow from being retriggered. You might need to increase this if the shortcut is play/pause looping.

By enabling this flow, once you have press home, the video playback automatically resume. But there is some delay, before the event dispatched to Automagic. 1 seconds stutter should be OK, since it automatically resume. But you can't never tap the pause button in the notification bar anymore. Since it will trigger the flow again, check chrome is not running, and send play again. This mean you never can pause anymore if chrome is not running.

So I made the second shortcut, which allow you to press this, then bypass the chrome checking and send pause to chrome. But this will trigger media session change. That's why I have to use FEP : Skip, with sleep 1s to protect from retrigger after sendng pause. Pressing the shortcut again will play again the video in the background.

If you pause the video when chrome is running, this flow still triggered, but not continue to send play to Chrome. Because chrome is running. So no intervention done when you are enjoying the video as usual.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
tsolignani
Posts: 187
Joined: 12 Jan 2019 11:53
Location: Vignola, Mo, Italy
Contact:

Re: executing action when Chrome goes to background

Post by tsolignani » 24 Jan 2020 10:02

Gorgeous! Thank you so much. I'll make some tries asap. Thanks!

Post Reply