Passing URL to MP3Player as a variable

I am using AMI to redirect a channel to a dialplan application that plays an MP3 file from a remote URL using the MP3Player app. It works fine when I have the file location hard coded but when I try to pass the location as a variable it is not picking up the value.

Here is the dialplan code that works when hard coded. I replaced the actual domain name with xxxxx.

[app-dropMessage]
exten => s,1,Answer()
exten => s,n,MP3Player(http://xxxxx.net/dss/sounds/users/29/Track2.mp3)
exten => s,n,Hangup()

Here is the dialplan code with a variable named {location}

[app-dropMessage]
exten => s,1,Answer()
exten => s,n,MP3Player(${location})
exten => s,n,Hangup()

and here is my AMI command

Action: Redirect
ActionID: DropMessage_1513176786
Channel: SIP/TRUNKP1-00001abc
Exten: s
Context: app-dropMessage
Variable: location=http://xxxxx.net/dss/sounds/users/29/Track2.mp3
Priority: 1

Is there something I am missing?

Just to test.

Does it work if you define the variable in your dialplan and then pass it to MP3Player?

[app-dropMessage]
exten => s,1,Answer()
 same => n,Set(Location=http://xxxxx.net/dss/sounds/users/29/Track2.mp3)
 same => n,MP3Player($Llocation})
 same => n,Hangup()

If it does then you may want to add in something like a NoOP to echo what the variable is or a Dumpchan() to show all variables and see what you are getting variable wise from AMI.

[app-dropMessage]
exten => s,1,Answer()
 same => n,Dumpchan()
 same => n,MP3Player(${location})
 same => n,Hangup()

Add a Noop(${location}) before MP3Player() cmd and share your cli output

Thanks for the reply but setting the variable in the dialplan didn’t work either. It would appear that the MP3Player application is not accepting a variable for the location.

I’m testing with an old version but it looked like the application accepts the variable here.

   -- Executing [9503@kiniston-intern:2] Answer("SIP/7124kiniston-00106ab1", "") in new stack
    -- Executing [9503@kiniston-intern:3] Set("SIP/7124kiniston-00106ab1", "Location=https://archive.org/download/testmp3testfile/mpthreetest.mp3") in new stack
    -- Executing [9503@Kiniston-intern:4] MP3Player("SIP/7124kiniston-00106ab1", "https://archive.org/download/testmp3testfile/mpthreetest.mp3") in new stack

[Dec 13 15:19:47] NOTICE[5794]: app_mp3.c:133 timed_read: Poll timed out/errored out with 0

I’m not sure if the the application handles https streams and I don’t have a working http stream to try, unfortunately your stream url is obfuscated so I can’t test with live data.

This is somewhat new to me so excuse me for asking but how can I see the cli output?

Here is the actual URL that I am using to test with. You are welcome to use it for testing. It is just a brief voice recording.

It looks like the forum software ‘Helpfully’ turned your link into a player.

Try formatting it with the preformatted-text button and pasting the url again.

1 Like
http://digitalspeech.net/dss/sounds/users/29/Track2.mp3

Try this one

Works just fine in my environment being passed as a variable.

exten => 9503,1,NoOP()
 same => n,Answer()
 same => n,Set(Location=http://digitalspeech.net/dss/sounds/users/29/Track2.mp3)
 same => n,MP3Player(${Location})
 same => n,Hangup()

Interesting, I will try your method again. Thanks.

Ok, setting the variable in the dialplan worked. Now I will see if I can pass it from the AMI command.

I got it to work by setting the variable in the Dial Plan but not when it is being passed by the ami command. Here is the output.

[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Executing [s@app-dropMessage:1] Answer(“SIP/TRUNKP1-00001afe”, “”) in new stack
[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Executing [s@app-dropMessage:2] NoOp(“SIP/TRUNKP1-00001afe”, “”) in new stack
[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Executing [s@app-dropMessage:3] MP3Player(“SIP/TRUNKP1-00001afe”, “”) in new stack
[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Spawn extension (app-dropMessage, s, 3) exited non-zero on ‘SIP/TRUNKP1-00001afe’

Here is the AMI command

Action: Redirect
ActionID: DropMessage_1513241973
Channel: SIP/TRUNKP1-00001afe
Exten: s
Context: app-dropMessage
Variable: Location=http://digitalspeech.net/dss/sounds/users/29/Track3.mp3
Priority: 1

Here is the Dial Plan

[app-dropMessage]
exten => s,1,Answer()
exten => s,2,NoOp(${Location})
exten => s,3,MP3Player(${Location})
exten => s,4,Hangup()

I got it to work by setting the variable in the Dial Plan but not when it is being passed by the ami command. I added a NoOp command to show the variable value but it is not showing anything.

Here is the AMI command

Action: Redirect
ActionID: DropMessage_1513241973
Channel: SIP/TRUNKP1-00001afe
Exten: s
Context: app-dropMessage
Variable: Location=http://digitalspeech.net/dss/sounds/users/29/Track3.mp3
Priority: 1

Here is the Dial Plan

[app-dropMessage]
exten => s,1,Answer()
exten => s,2,NoOp(${Location})
exten => s,3,MP3Player(${Location})
exten => s,4,Hangup()

Here is the output from the log

[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Executing [s@app-dropMessage:1] Answer(“SIP/TRUNKP1-00001afe”, “”) in new stack
[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Executing [s@app-dropMessage:2] NoOp(“SIP/TRUNKP1-00001afe”, “”) in new stack
[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Executing [s@app-dropMessage:3] MP3Player(“SIP/TRUNKP1-00001afe”, “”) in new stack
[2017-12-14 08:59:30] VERBOSE[20468][C-00000c64] pbx.c: Spawn extension (app-dropMessage, s, 3) exited non-zero on ‘SIP/TRUNKP1-00001afe’

I’m not an AMI guy, But I don’t see that the Redirect action supports passing in a variable.

I think the problem is that the Redirect command does not pass variables. That’s stupid.

Yes, I’m sure that is the problem. Maybe I can send two AMI commands? One using SetVar to set the variable of the app and then send the redirect command.

Use Multiple Inheritance adding “__” (two underbar characters) in the variable name

Variable: __Location=http://digitalspeech.net/dss/sounds/users/29/Track3.mp3

Redirect doesn’t support variables so Inheritance won’t help.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+15+ManagerAction_Redirect

I got confused, I didnt read you were using redirect, there is no variable parameter on the redirect action, instead you can use origiante action to a local channel with the redirect command

1 Like