Page 1 of 1

Detect any audio on media stream?

Posted: 01 Mar 2018 12:38
by nogaff
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.

Re: Detect any audio on media stream?

Posted: 01 Mar 2018 15:05
by Desmanto
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.

Re: Detect any audio on media stream?

Posted: 01 Mar 2018 15:14
by Martin
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