title: Stream Audio directly from an url to Web Browser in C# & ASP.NET MVC?
body: <p>I'm using ASP.NET MVC and C# for a project. </p>
  
  <p>One task is: when a user clicks on a link, it needs get the id from the link, then use this link to generate an external link, which is a audio file, then play it in web browser (not save as file).</p>
  
  <p>The current solution is: download the audio file from the external link, get the bytes, then put it in the response as audio/wav</p>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; StreamAudioAsync(string id)
  {
      var response = Request.CreateResponse(HttpStatusCode.Moved);
      var data = GetAudio(id);
  
      if (data != null &amp;&amp; data.Length &gt; 0)
      {
          response.StatusCode = HttpStatusCode.OK;
          response.Content = new ByteArrayContent(data);
          response.Content.Headers.ContentType = new MediaTypeHeaderValue("audio/wav");
      }
  
      return response;
  }
  
  private byte[] GetAudio(string id)
  {
      string accessKey = Cp.Service.Settings.AccessKey;
      string secretAccessKey = Cp.Service.Settings.SecretAccessKey;
  
      string url = string.Format("https://....../......php?access_key={0}&amp;secret_access_key={1}&amp;action=recording.download&amp;format=mp3&amp;sid={2}", accessKey, secretAccessKey, id);
  
      byte[] data = null;
  
      try
      {
          using (var wc = new System.Net.WebClient())
          {
              data = wc.DownloadData(url);
          }
      }
      catch //(Exception ex)
      {
          //forbidden, proxy issues, file not found (404) etc
          //ms = null;
      }
  
      return data;
  }
  </code></pre>
  
  <p>This will download the audio data first. Is there a way to stream the audio stream from the url directly to the response? so that, the server will not hold the data <code>bytes[]</code> in memory? Sometimes, the data size is huge.</p>
  
  <p>Thanks</p>