【问题标题】:How can I play multiple files in an AGI script?如何在 AGI 脚本中播放多个文件?
【发布时间】:2009-08-24 15:58:03
【问题描述】:

我可以使用以下方式将多个文件一起流式传输:

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

但是,这不会返回播放文件时用户按下的键。所以,我使用了$AGI->stream_file,它返回按下的键,但只播放一个文件。

我需要能够同时播放多个文件,播放应该在用户按下一个键的那一刻停止,并且我应该知道按下了哪个键。

我如何做到这一点?

【问题讨论】:

  • 你运行的是什么版本的 Asterisk?

标签: perl asterisk telephony


【解决方案1】:

这应该可行:

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).

您可以稍微缩短代码(例如,将循环收紧为 do/while),但这种方式可读性很强。

【讨论】:

    【解决方案2】:

    后台命令等待用户输入扩展名并自动将其发送到那里,或者如果 i 扩展名不存在,则发送到该扩展名。

    改用读取命令; Read 会将任何用户键存储到变量中:

    读取(SomeVar,file1,10);将最多 10 位数字读入 SomeVar SayDigits(${SomeVar})

    我认为 Asterisk 现在支持 Read 命令中的 file1&file2 内容,但我不知道它是从哪个版本开始的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多