IVR control of Playback() - selecting files within a folder


I’m new to Asterisk and learning about it’s capabilities. I’m trying to get my head around my current challenge within my project.

I’d like callers to be able to flip through sound files, saved in a particular folder. I’d like to program it so if they press a particular number, it flips to the next file in that folder. Files are going to be added by other callers. As a result, the folder is going to be constantly growing. Files are all saved with a time stamp. Ideally the playback control would not be randomly selecting another file.

Can Asterisk query a folder for how many files are in it? Then should I load those files into an array? That sounds like a possible performance cost for the caller.

It’d be great if ControlPlayBack() had another option to move to the next file in the folder. Is this possible?

Can Asterisk handle some thing like this? Can anyone shed some lights on some possible routes?

Thanks for your time! I really appreciate it and any insights!

Asterisk is already doing lots of stuff for us so it will not be good to expect this feature in asterisk. The thing you want to achieve can be simply done with the help of running an external scrip created in PHP or PERL. Here is how I did it.
I Create a script in perl that will search a particular folder for files and store them in an array. Then i generated a random number in the range of the length of array and used it as seed to get a random file to be selected.

in script.pl

@files = readdir($dh);
my $len = @allfiles;
$len = $len -1;
my $choose = rand($len);
my $ext = substr($allfiles[$choose],-3);
$allfiles[$choose] =~ /(.*).(\w\w\w)$/;
print STDOUT “SET VARIABLE track $1\n”;

in extensions.conf

exten => 1234,1,Answer
exten => 1234,n(get_track),SET(trk=)
exten => 1234,n,Agi(/root/scripts/bgt_rand_track.pl)
exten => 1234,n,SET(__TRACK=${track})
exten => 1234,n,Playback(${PATH}/${TRACK})
exten => 1234,n,Goto(get_track)

You can then modify it according to your needs.