How to time-limited playback sound using dialplan


I was thinking if it is possible to play a sound file for a limited amount of time. currently what i can use is –

exten => _XXXX,1,Playback(soundfile)

by this, the ‘soundfile’ plays to the end of the file before returning the control. how do i playback a sound for, say, 10 seconds and return the control?


Look up ‘background’ and ‘wait’ applications.

exten => _X.,1,Background(soundfile)
exten => _X.,n,Wait(10)
exten => _X.,n,Hangup() ; or do something else etc.


Background plays the whole file, so you will need to record the file for the correct length. and use it as below. but to be honest you may as well use playback

Note Its best to point to a context and use the m option and put no options in the context defined so that the caller cant interrupt the message.

another alternative is to have the file as wav musiconhold file and call that using WaitMusicOnHold(5)


thanx ianplain and raffles. the WaitMusicOnHold(10) kind of met my requirements. but i wanted to state the file to be played and time to be played. for example how to play a 60 sec soundfile for a 10 sec duration? :smiley:… thanx.


Simple you define the file as a musiconhold class and define thats the class you want played.


thanx… :smiley:… i actually did the following and it is working as i wanted…
in /etc/asterisk/musiconhold.conf

mode = files
directory = /var/lib/asterisk/mysounds/

and dialplan

exten => _X.,1,Answer()
exten => _X.,n,StartMusicOnHold(myclass)
;this actually returns the control unlike MusicOnHold
exten => _X.,n,Wait(10)
exten => _X.,n,Hangup()


You could cut a line out and use WaitMusiconhold(10)


But that would need SetMusicOnHold before calling WaitMusicOnHold. because i want to change the musiconhold class used each time.

is equivalent to


isnt it?