How to detect when a playback or localplay file has finished?

Dear all,

Every week I play an audio file with the GB2RS news over several repeaters, using the LOCALPLAY function.

I need to run some commands after the file playback is completed to put the system back to normal but as the file runs for a different duration each week, as the news is different, I need to find a way to detect when the playback has completed.

Any ideas on how to do this?

I thought maybe the events management subsystem might work for me but I can’t find much info or documentation about that, to enable me to learn enough about it to make it work. Some of the URLs for links to the old ohnosec site are now gone.

Thanks for any ideas or info received,
73,
Matt G4RKY

I might suggest this approach, but there are many ways…

If you use a macro to execute the localplay, the next item in the macro would execute what you want to do after.

Keep it simple…

Programmatically detect the length of the audio file before playing it, so that when you execute the localplay command you can simply wait or sleep for the length of the audio file (maybe add 1 or 2 extra seconds for padding) before executing the rest of your commands.

Hey… :blush:

As per my knowledge, One option is to use a script that monitors the playback status. You could set it up to detect when the playback process ends and then execute your commands. If you’re using a specific software for playback, check if it has a logging feature that indicates when playback completes.

I hope this will help you!

Regards!

Hi Mike and thanks for the reply.

I did try this and found that the next irem in the macro executes immediately after the audio playback commences! It was a while ago since I tried this, so I will try it again to be sure.

I’ll feedback the results…

73,
Matt

Hi Mason,
Thanks for your reply, but I don’t know how to programatically work out the length of playback of the file - all I know is the filesize in bytes - I imagine it can be done that way but no clue as to how to calculate the duration from that…
73,
Matt

Hi Roseanne23,
Thanks for your reply, in fact I am using the built in feature in Allstarlink to play the file back and ideally wanted to find a way within allstarlink to achieve this rather than start to use external scripts. As far as I know, Allstar uses an internal process to play the file, I don’t think it uses an external process for playback.
73’s

Matt

You can use ffprobe:

#!/bin/bash

# Path to the audio file
audio_file="path/to/your/audio/file.mp3"

# Get the duration of the audio file in seconds and add 2 seconds buffer
sleep_duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$audio_file")
sleep_duration=$(echo "$sleep_duration + 2" | bc)

# Sleep for the calculated duration
sleep "$sleep_duration"

# Execute the next command
echo "Sleeping for $sleep_duration seconds is complete. Executing the next command..."
# Add your next command here

Perhaps the second item in the macro could be a shell script waiting for the transmitter to drop.

But yea, I can see how that would skip through that.

Personally, I would do the whole thing from a shell script where you can have a more complete control…