Music on hold from remote file?

Hi just a quick question in regards to the music on hold. i am using a mysql table musiconhold which have a field directory and application. currently i use local file to be played in the music on hold, is there anyway i can use remote file which is available on mp3 format.

can anyone please guide what will be the value in the directory and application field? i assume mode will be custom.

Thank you

For this, you will have to rely on an external program/script, I don’t know of any other way to do this using musiconhold.conf directly. An in-house solution we use is a bash script that acts as a wrapper for ffmpeg. This way, we can play anything as moh, just by passing it with a link or file.

#!/bin/bash

file="$1"

if [ -z "$file" ]; then
  exit 1
fi

exec ffmpeg -hide_banner -loglevel error -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 150 -i "$link" -f s16le -ar 8000 -ac 1 -af volume="0.65" -sample_fmt s16 -

save it somewhere and give it execute permission.

then, in musiconhold.conf, we put this:


[remote]
mode = custom
application=/my/script/path <filename.mp3 or https://link.com/filename.mp3>

This will cause Asterisk to execute our script, which will then take care of the logic of retrieving and converting the files with ffmpeg, sending output to stdout, and already in the format that Asterisk expects. This script I showed you is just an example, but you can do much more exotic things with a little creativity and a few tricks.

Oh, and spoiler alert! This has served us for years, across multiple installations, and with almost no problems.

Thank you so much, Let me check it out. but i have tried to put application = /usr/bin/mpg123 -y -q -s --mono -r 8000 -f 8192 -b 2048 -s https://storage.googleapis.com/xxx.mp3 and it did not work. asterisk is showing warning WARNING[790]: res_musiconhold.c:811 monmp3thread: poll() failed: Interrupted system call

Which MPG123 version are you using? URLs with https only work, unless I’m mistaken, from version 1.30.0 onwards.

I am running version 1.25.6

I am using https. by the way if i remove the https link and put the file local with the same command i can hear the music on hold

mpg123 still supports http in versions beyond 1.30; I have 1.33.2 and I am able to play back files over https or http.

Usually the monmp3thread error happens when the application being called isn’t sending data. Your command looks fine and should be sending data Asterisk likes without any special handling. This command is very similar to what I use for my icecast streams; and they work with mpg123 (and ogg123 too).

My guess is it’s taking mpg123 too long to start sending data due to the fact the file is “really remote” and asterisk gets angry. If you can replace the URL with a local file and it works; then this is the only thing I can think of.

Thank you so much @dewdude and @Knuppalex2023

Upgrading the mpg123 version have resolved the issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.