ControlPlayback: Wait for other DTMF while playback

Hi there,

I revived our crappy phone music player idea again.
As recommended by ambiorixg12 in this thread, I switched over to ControlPlayback.

This works fine, I converted the files into WAV/PCM.

I didn’t know how to read all the music files in Asterisk itself so I’m still using a Perl script.

Is it possbile to wait for and react to other DTMF inputs than supplied by ControlPlayback?

My idea is to also listen for volume change and song skip etc.

First idea was by using wait_for_digit, but unfortunately it seems that my AGI request is waiting for finishing playback.

sub PlayRandomSong
{
  $randomFile = RandomSongPath();
  
  # Play song and set control; scheme: skipms,ff,rew,stop,pause,restart
  $AGI->exec('ControlPlayback',"$randomFile,5000,9,7,0,5,*");
  
  # TEST volume control:

  my $input = $AGI->wait_for_digit(-1);
  
   if ($input == 2)
  {
    $AGI->exec('Set','VOLUME(TX)=' . $volume + 1);
  } 
  elsif ($input == 8)
  {
    $AGI->exec('Set','VOLUME(TX)=' . $volume - 1);
  }  
}

My extensions.conf:

[line1]
exten => raspbx2020,1,Answer()
same => n,Set(VOLUME(TX)=3)

same => n,AGI(/var/lib/asterisk/playback/pbxaudiobackend.pl)


;same => n,Hangup()

Is there a possbilitiy to wait for a special DTMF input while playing a file?

Thanks,

Nico

VOLUME function takes an option, p, to enable DTMF volume control with * and # keys. So something like this might work (did not test it myself though):

[line1]
exten => raspbx2020,1,Answer()
same => n,Set(VOLUME(TX)=3,p) ; p option allows * and # to increase and decrease volume
same => n,AGI(/var/lib/asterisk/playback/pbxaudiobackend-randomfilelookup.pl) ; modify your AGI to just set randomFile only
same => n,ControlPlayback(${randomFile},5000,9,7,0,5,1) ; no more * to restart - also the call control is out of AGI and back in your dial plan quickly
1 Like

Dear Penguinpbx,

thanks for your answer!
This does work in general but unfortunately it still ignores DTMF controls during playback (except for the ControlPlayback ones).

Can I for example start ControlPlayback in a second asynchronous task so that the dialplan already starts the next application (wait for digit)?

Thanks,

Nico

Local channels might be another option – again, I did not try this, but maybe it helps you:

[line1]
exten => raspbx2020,1,Answer()
same => n,Set(VOLUME(TX)=3,p) ; p option allows * and # to increase and decrease volume
same => n,AGI(/var/lib/asterisk/playback/pbxaudiobackend-randomfilelookup.pl) ; modify your AGI to just set randomFile only
same => n,Dial(Local/${randomFile}@local1/n)

[local1]
exten => _XXX,1,NoOp(assumes randomFile is a three digit number eg 123.wav)
same => n,ControlPlayback(${EXTEN},5000,9,7,0,5,1) ; no more * to restart - also the call control is out of AGI and back in your dial plan quickly
1 Like

Thank you again, PenguinPBX!
I still get an error and only a busy tone on the line and I assumed that it’s maybe from the spaces in the filenames, but unfortunately it also does not work without them:

=========================================================================
Connected to Asterisk 13.29.2 currently running on raspbx (pid = 1000)
  == Using SIP RTP TOS bits 184
  == Using SIP RTP CoS mark 5
       > 0xb450b6e0 -- Strict RTP learning after remote address set to: 192.168.123.1:7082
    -- Executing [raspbx2020@line1:1] Answer("SIP/line1-0000001b", "") in new stack
       > 0xb450b6e0 -- Strict RTP switching to RTP target address 192.168.123.1:7082 as source
    -- Executing [raspbx2020@line1:2] Set("SIP/line1-0000001b", "VOLUME(TX)=2,p") in new stack
    -- Executing [raspbx2020@line1:3] AGI("SIP/line1-0000001b", "/var/lib/asterisk/playback/pbxaudiobackend_randomfile.pl") in new stack
    -- Launched AGI Script /var/lib/asterisk/playback/pbxaudiobackend_randomfile.pl
    -- <SIP/line1-0000001b>AGI Script /var/lib/asterisk/playback/pbxaudiobackend_randomfile.pl completed, returning 0
    -- Executing [raspbx2020@line1:4] Dial("SIP/line1-0000001b", "Local//var/lib/asterisk/playback/PCM/Never Again@local1/n") in new stack
[2020-07-25 16:38:39] NOTICE[12881][C-0000001b]: core_local.c:756 local_call: No such extension/context @default while calling Local channel
    -- Couldn't call Local//var/lib/asterisk/playback/PCM/Never Again@local1/n
  == Everyone is busy/congested at this time (0:0/0/0)
    -- Auto fallthrough, channel 'SIP/line1-0000001b' status is 'CHANUNAVAIL'

Unfortunately the filenames are real names, can I also mask this with “NoOp”?

Thanks,

Nico

Try that as your file name that you place into /var/lib/asterisk/playback/PCM/ directory - just a try.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.