terminal bash command question, how to monitor grep and repeat command infinitely?

orangpelupa

Elite Bug Hunter
Legend
so the context:

I want to make a bash terminal command that will launch VLC to stream a video, and then when VLC is no longer in the foreground (VLC automatically goes to the background when the stream is interrupted too long), it will repeat the command to launch VLC to stream again.

I got the working separate command codes, but I don't have any idea how to make these work into one command that keeps repeating.

  1. To launch VLC and starts streaming:
Code:
am start -a android.intent.action.VIEW -d rtsp://theurl

This will launch/bring to the foreground the default app for RTSP (in this case, VLC) and starts streaming.

2. To check whether VLC is still in the foreground or not
Code:
dumpsys activity activities | sed -e '/mResumedActivity/!d' -e '/vlc/!d'

This will return something like this when VLC is in the foreground.

Code:
 mResumedActivity: ActivityRecord{b43545d u0 org.videolan.vlc/.gui.video.VideoPlayerActivity t11827}

and will return nothing in the terminal if VLC is not in the foreground.

so maybe the code will be doing something like this?

every 1 second, check for VLC is in the foreground or not (using code number 2). If VLC is not in the foreground, launch vlc with the streaming URL (using code number 1).

i posted this question here too https://superuser.com/questions/168...peated-after-an-activity-no-longer-foreground
 
Why not use a program ?
back in the dial up days BT would auto disconnect you every 2 hours (you were allowed to reconnect, it was just to stop people leaving it connected 24/7)
this was no good if you wanted to download something overnight so I used a program that every 2 hours 1 minute would click on the reconnect button.
cant remember what it was called it had 2 methods of clicking on the button the fist was just an X/Y co ordinate system the other was by detecting the identifier of the control and sending windows the correct api message.
try one of these
https://push-the-freakin-button.en.softonic.com
https://windowsreport.com/software-automate-mouse-clicks/

ps: is this just because your too lazy to click on vlc ?
 
Last edited:
The vlc will be running unattended. Thus I need it to auto recover when the stream gets interrupted.

Anyway I've found a string of commands that works on the superuser post I linked above. Someone also replied with a supposedly better command but I hadn't get the chance to try whether it work or not.
 
Back
Top