Friday 19 July 2019

How to stream a video file to play on the browser, when the file exist in a different folder than the website?

How to stream a video file to play on the browser, when the file exist in a different folder than the website? RSS

3 replies

Last post Dec 05, 2013 11:09 AM by markfitzme
  • Robin2000Robin2000
    None
    0 Points
    5 Posts

    How to stream a video file to play on the browser, when the file exist in a different folder than...

    Dec 05, 2013 10:30 AM|LINK
    Hi,
    I have a website running on DNN7.1. We store all our documents, videos that we serve to the users (which are uploaded by users too) in different location than the website. Currently we are using HttpResponse's TransmitFile method to send files. It works fine for pdf, pngs etc. but for mp4 files we want to play it on the browser. I have created aspx page with html5 video element as shown below.

    <video class="something" width="320" height="240" controls>
    <source src="/FileServer.aspx?file=clips/vedio1.mp4" type="video/mp4">
    </video>
    video element uses FileServer.aspx, which is responsible to transmit the file. Code for FileServer.aspx page_load event handler is shown below (removed not needed code for readability).
    string fileName = Path.GetFileName(fileFullPath);
    string fileLength = new System.IO.FileInfo(fileFullPath).Length.ToString();
    string fileContentType = Utility.GetMIMEType(fileName);
    
    fileName = "\"" + System.Web.HttpUtility.HtmlEncode(fileName) + "\"";
    
    Response.Clear();
    Response.ContentType = fileContentType;
    Response.AddHeader("Content-Length", fileLength);
    Response.AddHeader("Content-Disposition", "inline; filename=" + fileName);
    Response.ContentEncoding = System.Text.Encoding.Default;
    
    Response.TransmitFile(fileFullPath);
    Response.End();
    Html5 video element appears on the browser fine and when I click it, it plays fine but I can't forward it or reverse the video. This will cause the video to stop and nothing else happens. I can only pause and play it. I am thinking TransmitFile method might not be suitable for my scenario. How do I acheive allowing forwarding and reversing the video using Response. I put the video under the website and used int the vidioe element (without FileServer.aspx) and all the video controls work fine. But I am not allowed to move the files to website folder, they will stay in a seperate folder or even seperate disk. How do I make playing video work for my scenario. Any help is greatly apprciated.

    Thanks,
    VIDEO ASP.NET MP4
  • AidyFAidyF
    All-Star
    37441 Points
    9076 Posts

    Re: How to stream a video file to play on the browser, when the file exist in a different folder...

    Dec 05, 2013 10:45 AM|LINK
    Easiest thing will be to find a client-side control (Flash, java etc) that does what you need to do.  Google for flash-based video players and see what is out there.
    VIDEO ASP.NET MP4
    I'm afraid I no longer use this forum due to the new point allocation system.
  • PatriceScPatriceSc
    All-Star
    44920 Points
    16038 Posts

    Re: How to stream a video file to play on the browser, when the file exist in a different folder...

    Dec 05, 2013 10:48 AM|LINK
    Hi,
    Good question. Not 100% sure by my approach would be first to play directly the video, use F12 Network tab to see http requests and play with the video (play, seek etc...). You should then be able to see what the browser sends to the server to get at a particular position. I would expect that the browser sends a particular header (range if I remember) to ask for a particular portion of the file.
    If confirmed you'll have then to handle this information and send back the relevant portion in your response.
    Depending on why you are not allowed to store the file on the server, another option could be perhaps to use a virtual folder pointing to a network location. The file is then technically speaking stored somewhere else while it is still directly reachable as an URL (and likely would be able to handle those byte-range requests...)


    VIDEO ASP.NET MP4
  • markfitzmemarkfitzme
    All-Star
    26061 Points
    5892 Posts

    Re: How to stream a video file to play on the browser, when the file exist in a different folder...

    Dec 05, 2013 11:09 AM|LINK
    What you describe is normal. To handle the other scenarios requires a streaming media environment. You just don't get that with transmit file, nor even with just standard video formats. That's why there are specialised streaming media servers to handle just this. I have yet to use it, but you may want to check out IIS's media services at: http://www.iis.net/media

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive