I have an mp3 file in my site. I want to output it as a view. In my controller I have:
public ActionResult Stream()
{
string file = 'test.mp3';
this.Response.AddHeader("Content-Disposition", "test.mp3");
this.Response.ContentType = "audio/mpeg";
return View();
}
But how do I return the mp3 file?
Create an Action like this:
public ActionResult Stream(string mp3){
byte[] file=readFile(mp3);
return File(file,"audio/mpeg");
}
The function readFile should read the MP3 from the file and return it as a byte[].
If your MP3 file is in a location accessible to users (i.e. on a website folder somewhere) you could simply redirect to the mp3 file. Use the Redirect() method on the controller to accomplish this:
public ActionResult Stream()
{
return Redirect("test.mp3");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With