How to stream partial content with ASP.NET MVC FileStreamResult

丶灬走出姿态 提交于 2019-12-05 01:46:46

There is a project on CodePlex which gives this exact functionality.

http://mediastreamingmvc.codeplex.com/

Take a look. It was created specifically for this scenario where you want to have an action representing a request for a virtual resource and return partial content if so requested without requiring the developer to do much to support it (an Action Filter and choice of Result types.)

  1. You have to implement this by yourself. And yes, this will work on IIS6.
  2. If you can use IIS7 you probably better to leverage on IIS7 extensibility (example).

Then you need to reimplement throttling module :)

The idea is to calculate bitrate of your video stream and then send as much as required to client. So you need (very briefly) to read a block from your stream and send it to client and sleep for a second.

Thread.Sleep(1000) is not really a good idea for handling IIS resources so you need to do stuff in async way. IAsyncResult will be your friend.

There is much room for all kinds of optimisations.

And the last thing... I made it working as plain httphandler, not as MVC ActionResult. If it's possible in your webiste, I'm recommending to do it as a handler.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!