Detect any audio on media stream?

Post your questions and help other users.

Moderator: Martin

Post Reply
nogaff
Posts: 1
Joined: 10 Oct 2017 20:57

Detect any audio on media stream?

Post by nogaff » 01 Mar 2018 12:38

Is there a way to trigger a flow when audio starts or stops on the media stream?

What I'd like to do is reset the media volume to a low level once a certain amount of time passes after the audio stops.

For example, let's say I've been watching videos in my web browser, or YouTube, or Instagram, and I've turned the volume up to 20. Once I stop watching anything, I want the flow to wait for 5 minutes and then set the volume back to 1.

I can't just use an "Activity Ended" trigger because even though I've stopped watching a video, I might still continue to use the app that the video was playing in. Therefore I really need the flow to react to the audio itself.

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

Re: Detect any audio on media stream?

Post by Desmanto » 01 Mar 2018 15:05

I also want to know if we can detect any sound produced by certain app. So far, you have only Trigger Media Session Changed. This will trigger every time at the media app using play, pause, stop, next, previous or any media related event. Because you want only when the audio stop, you should filter the event by adding expression, to filter if playback_state is 1 (stopped) or 2 (paused). When you play the video, flow still triggered, but can't continue to the main branch. At the main branch, use the sleep 5 minutes and finally set the volume to 1. You need to use AES - Stop, to make sure the timer get resetted when you play another video within 5 minutes.

The other method is using periodic timer with condition music active. But this will drain more battery and can't be reset when you play another video within 5 minutes.
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
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Detect any audio on media stream?

Post by Martin » 01 Mar 2018 15:14

I'm not aware about detecting if a stream is active except by periodically checking the condition Audio Stream Active. I assume that it does not consume a huge amount of additional battery when this condition is executed every few seconds when sound is playing however the effect on the battery could be dramatic when the condition is executed 24*7 when the device is not in use otherwise. Maybe a flow that checks the condition and then uses an action Sleep (without Keep device awake) in a loop could work quite ok and would let the device sleep when it's not in use.
Maybe some sort of sound/video-player app-detection could work and would likely use less battery.

Regards,
Martin

Post Reply