How to stream partial content with ASP.NET MVC FileStreamResult

前端 未结 3 1160
感动是毒
感动是毒 2021-02-20 06:46

We\'re using a FileStreamResult to provide video data to a Silverlight MediaElement based video player:

public ActionResult Preview(Guid id) {
    return new Fil         


        
相关标签:
3条回答
  • 2021-02-20 07:03

    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.)

    0 讨论(0)
  • 2021-02-20 07:07

    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.

    0 讨论(0)
  • 2021-02-20 07:14
    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).
    0 讨论(0)
提交回复
热议问题