tags:

views:

213

answers:

2

I am able to stream multiple files together using:

$AGI->exec('Background',"file1&file2&file3&file4")

However, this doesn't return the key pressed by the user when the files are being played. So, I used $AGI->stream_file, which returns the key pressed, but only plays a single file.

I need to be able to play multiple files together, the playback should stop the moment a key is pressed by the user, and I should know which key was pressed.

How do I achieve this?

+1  A: 

This should work:

my $keyPress;
# fill in your filenames as appropriate...
foreach my $file (qw(file1 file2 file3))
{
    $keyPress = $AGI->stream_file($file);
    last if $keyPress;
}

# by this point, $keyPress will contain what key was pressed,
# 0 if all files played to completion, or -1 if a hangup occurred
# (as per the documentation).

You could shorten the code a little bit (e.g. tighten up the loop into a do/while), but this way is pretty readable.

Ether
A: 

The Background command waits for the user to enter an extension and automatically sends them there, or to the i extension if it doesn't exist.

Use the Read command instead; Read will store whatever the user keys into a variable:

Read(SomeVar,file1,10); Read max 10 digits into SomeVar SayDigits(${SomeVar})

I think Asterisk now supports the file1&file2 stuff in the Read command but I don't know since what version it works that way.

Chochos