Solved Prompt Playback from external

Status
Not open for further replies.

RafalR

Silver Partner
Advanced Certified
Joined
Jun 18, 2020
Messages
12
Reaction score
6
Hi,
I would like to play audio file from external server. In that case I need to be able to download it first. I already found edossantos's post but it doesn't work for me.

Full C# code I use:

Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace FileDownloader
{
  public class FileDownloader
  {
    private async Task downloadFile(string uri, string fileName)
    {
      using (HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, uri))
      {
        using (HttpClient httpClient = new HttpClient())
        {
          using (HttpResponseMessage httpResponse = await httpClient.SendAsync(httpRequest))
          {
            byte[] byteArray = await httpResponse.Content.ReadAsByteArrayAsync();
            using (FileStream stream = File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            {
                stream.Write(byteArray, 0, byteArray.Length);
            }
          }
        }
      }
    }
    
        public void DownloadFile(string uri, string fileName)
        {
            downloadFile(uri, fileName).Wait();
        }
  }
}

CFD component:
1692778603241.png

There is no error in CFD but in 3CX Management Console in Call Flow Apps section.
1692778146167.png

I will be grateful for any help.
 
Remove the namespace from your C# script. Leave just the class.
 
Thank you. It works fine now.
 
  • Like
Reactions: edossantos
Status
Not open for further replies.