Asterisk cmd Playback
Created by: oej,Last modification on Tue 19 of Aug, 2008 [10:00 UTC] by JustRumours
Synopsis
Play a sound fileDescription
Playback(filename1[&filename2...][,options])Plays the specified sound file(s) (you need to omit the filename extension). Sound files are stored in the /var/lib/asterisk/sounds directory by default (the directory path can be changed in asterisk.conf).
Playback is Multi-Language-compliant. It will look in a subdirectory corresponding with the current language code (as set by the SetLanguage command, or the channel's default language code. Failing that, it will play the non-language-specific edition.
Playback will play the whole sound file(s), and when complete, return control. Compare with the Background command, which plays a sound file but returns control immediately, allowing Asterisk to perform other commands on this channel while the sound file is playing.
Options
skip: Play the sound file only if the channel has already been answered. If the channel has not yet been answered, the Playback command will return immediately without playing anything.noanswer: Play the sound file, but don't answer the channel first (if hasn't been answered already). Not all channels support playing messages while still on hook.
If neither skip nor noanswer options are specified, then the Playback command will first answer the channel (if it hasn't been answered already) and then play the sound file.
Note: The options wont work if there are spaces between the filename, the comma and the option(s).
Example
exten => 500,1,Playback(tt-weasels,skip)Return code
On completion, ${PLAYBACKSTATUS} contains either "FAILED" or "SUCCESS".Troubleshooting
Playback is not affected by timing, unless internal_timing is turned on in asterisk.conf.See also
- ControlPlayback: Play a sound file with fast forward, rewind and exit controls
- Background: Play a sound file while processing other commands
- Playtones: Play a tone sequence
- Asterisk cmd Progress: Prepare to play early audio to the caller without answering the channel
- MP3Player: Play an MP3 sound file
- MusicOnHold
- Sound Files
- Asterisk tips answer-before-playback: Why you need to answer before sending sound on a channel
Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Comments
333Playback with music background (MOH) support
exten => s,n,Playback(instructions|m) ;play instruction message, with music background
The same thing should be done for Background application.
I don't know if it's easy or not to do this, hope that a similar feature should be implemented.
Best regards. Paolo
333examples to show support for multiple sound files
.
The most important feature of playback, imho, is its flexibility for playing multiple sound files separated by "&".
exten => s,n,Playback(file1&file2&file3&....)
Spaces around "&" are not tolerated, they are recognized as a part of the filename and asterisk will log a "file not found in any format" error.
You can also use variable names mixed in with literal names for filenames, for eg.
exten => s,n,Playback(${var_file1}&literal_file2&literal_file3&${var_file4}&....)
You can also use variables for parts of a file name, eg.
exten => s,n,Set(MyLang=english)
exten => s,n,Playback(for-${MyLang}-press)
Playback CANNOT be INTERRUPTED with touch tone input, for interruptible audio use Read() or Background(). But Read DOES NOT play multiple sounds files.
The sound filenames in playback can be names in the asterisk sounds dir OR they can be absolute path names.
Playback easily accommodates several hundred chars long filenames string. Eg.
exten => s,n,Playback(/var/lib/asterisk/sounds/what-time-it-is&/var/lib/asterisk/sounds/freezing)
The full paths were not needed in the above example because we were referring to files in the asterisk sounds dir.
Another example illustrating the flexibility of Playback filenames support -
exten => s,n,Set(Files2Play=$The attachment id given is not valid.&$The attachment id given is not valid.)
exten => s,n,Set(Files2Play=${Files2Play}&file_3&file_4)
exten => s,n,Playback(${Files2Play})
333can jump to priority n+101
If the global option priorityjumping is enabled, or option "j" is passed to Playback, it will jump to priority n+101 if a file to be played doesn't exist.
Silly example:
(if 'file' doesn't exist, it will end up on priority 700)
(...)
priorityjumping=yes
(...)
exten => s,400,NoOp(lala)
exten => s,n,NoOp(var1: ${var1})
exten => s,n,Playback(file)
exten => s,n,Goto(600)
exten => s,500,Set(var2=x)
exten => s,n,GotoIf(test?600)
exten => s,n,Set(anothervar=)
exten => s,n,Goto(700)