CyCoreSystems / ari

Golang Asterisk REST Interface (ARI) library
Apache License 2.0
180 stars 74 forks source link

Pause and resume MOH to play prompts #170

Closed gordongrech closed 6 months ago

gordongrech commented 6 months ago

Hello, I am building a distributed queue app. Part of the app is paying music and periodic announcements while the call is queued. I would need the music to stop, announcement plays and music resumes from where it stopped.

I have tried achieving this using pause on music, playing the announcement and unpausing the musing again, but I get an error "failure in playback: timeout waiting for playback to start" whenever I play the announcement.

Another approach is to keep track of music playback duration and re-start music playback at an offset. I went through the documentation and issues to find a way to use something like playback with offsetMs however I cant seem to find the option available in the API.

Can anyone please guide me in the right direction if I am missing something?

Thanks

Ulexus commented 6 months ago

You cannot play a different audio file to a channel (or bridge) while another is playing (paused or not). I would:

  1. pause the music
  2. create a new channel
  3. bridge the new channel into the existing bridge and/or channel
  4. play the announcement to the new channel
  5. unbridge the new channel
  6. tear down the new channel
  7. resume music

That said, there is also the Asterisk-native MusicOnHold feature, which is accessible as player.MOH() and player.StopMOH() (player here refers to a channel handle or a bridge handle), which would be the more usual way of doing this.