ARI: Wait for playback sound to end

I’m using a C#/NET library to implement my ARI conference app.

I’m implementing authentication prior to adding a conference user into a conference.
If a user fails to authenticate then it should play a sound and fire the StasisEnd event / Hangup.

If the auth function AddUser returns false then I get an endless loop of the playback sound.

If I force hangup with: Client.Channels.Hangup(e.Channel.Id); in the OnStasisEndEvent function like below, the app hangs up the call before the sound is done playing.

private static void c_OnStasisEndEvent(object sender, StasisEndEvent e)
{
    Client.Channels.Hangup(e.Channel.Id); //here

    if (e.Application != AppConfig.AppName) return;

    var conf = Conference.Conferences.SingleOrDefault(x => x.ConferenceUsers.Any(c => c.Channel.Id == e.Channel.Id));
    if (conf == null) return;

    conf.RemoveUser(e.Channel.Id);

}

AddUser:

 public bool AddUser(Channel c) 
 {

     ..............

     else //if there aren't any conferences, play audio
     {
                PlayFile("no-empty-conferences", c.Id);
                PlayFile("pls-try-call-later", c.Id);
               
                addUser = false;
      }

    return addUser;
}

What can I do so the playback sound completes then hangup call ?

As you’re using the SimpleConfExample from the Github repo for AsterNET.ARI, would it not be better to ask related questions there?

Again, your questions relate less to ARI than C#.

However, if you want to know if a playback has finished, you need to wait for the PlaybackFinished event to be fired. Check the playbackId to be sure it’s the playback your waiting for.

An example of this exists here: https://github.com/skrusty/AsterNET.ARI/blob/master/AsterNET.ARI/Helpers/SyncHelper.cs

[Note: not a very good example, but an example non the less]

Using playback like below seems to do the job:

SyncHelper.Wait(_client.Channels.Play(c.Id, "sound:no-empty-conferences", "en", 0, 0, Guid.NewGuid().ToString()), _client);

Thanks.