Avoid dead air playing files from playlist

I would like music is played when no show is broadcasted.
I found a way to check if stream is silent (here)
I’m writing a script to start streaming music, after 20 seconds of silence, with ffmpeg:

ffmpeg -re -i playlist.txt -content_type audio/mpeg -f mp3 icecast://source:mypwd@localhost:8001/main

The problem is I don’t know how to regain the stream (stopping ffmpeg stream) when a new live broadcasting on port 8001 starts.

Any idea?

Instead of using an external task to check for silence, we use the “Outro Autoloading Playlist” on the General Settings page to provide content when nothing else is scheduled.

–Bob.

Thanks for your answer!
You are right, that’s the simplest solution and probably it’s what I’m going to do. The only problem is I need to fill the calendar with shows (for the entire day) to use Outro Autoloading Playlist, am I right?
I would prefer a playlist streamed when no show is broadcasted

giucas