4

I'm working on an MVC webapplication that streams data from many resources.
My problem is when want to get data (music file) from a stream resource and then stream it to my web page, I don't know how not to download completely and then stream it to my web page.
Here is my webapi code:

[HttpGet]
public HttpResponseMessage Downlaod(int Data)
{
    WebClient myWebClient = new WebClient();

    Uri u =new Uri("https://api.soundcloud.com/tracks/" + Data + "/stream?client_id=*******************");

    byte[] myDataBuffer = myWebClient.DownloadData(u);
    MemoryStream st = new MemoryStream(myDataBuffer);
    /*heres when i download data and convert it to memory stream*/
    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

    result.Headers.AcceptRanges.Add("bytes");
    result.StatusCode = HttpStatusCode.OK;
    result.Content = new StreamContent(st);
    result.Content.Headers.ContentLength = st.Length;
    result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/octet-stream");
    return result;
}

I want to stream immediately when I receive bytes from my resource.

note: I'm not asking about how to stream data to the client it's about streaming from server to server. I want to get file from another server and stream it to my clients without downloading the full content before start streaming.

note2: I also don't want to download the full content in once because the full content is very big, I want to get a byte from my content and then send that byte to the client not downloading the full content. I think I'm doing it in wrong way and it is not possible with an MVC application if anyone can introduce an application that can proxy bytes from destination to client it would be the answer. the main reason that I want this,is to proxy a music file from my content server to a javascript music player and not to expose the main file.

  • 1
    possible duplicate of [ASP.NET MVC Audio Streaming](http://stackoverflow.com/questions/9383380/asp-net-mvc-audio-streaming) – Backs Aug 09 '15 at 07:04
  • no my question is about how to not download the full content and get one byte from remote server and send that into my clients that above code downloads the full content and then starts streaming that slow down the opration – Mohammad Reza Farahani Aug 09 '15 at 07:30
  • 3
    Possible duplicate of [Copy file from remote server to client browser via my server without writing the entire file to disk or memory](https://stackoverflow.com/questions/15843059/copy-file-from-remote-server-to-client-browser-via-my-server-without-writing-the) – Dr. Greenthumb Oct 29 '18 at 21:01

0 Answers0