How to time-limited playback sound using dialplan

Hello,

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

[samplecontext]
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?

Thanx.

Look up ‘background’ and ‘wait’ applications.

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

Hi

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)

Ian

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.

Hi

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

Ian

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

[myclass]
mode = files
directory = /var/lib/asterisk/mysounds/

and dialplan

[mycontext]
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()

Great

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

Ian

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

is equivalent to

StartMusicOnHold(myclass)
Wait(10)

isnt it?