How to stream an MP3 from an ASP.NET MVC Controller Action

前端 未结 7 1534
时光说笑
时光说笑 2020-12-29 16:31

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\';
            


        
7条回答
  •  一整个雨季
    2020-12-29 17:05

    You should return a FileResult instead of a ViewResult:

     return File(stream.ToArray(), "audio/mpeg", "test.mp3");
    

    The stream parameter should be a filestream or memorystream from the mp3 file.

提交回复
热议问题