I'm serving video from an MVC3 site, with the controller action that returns the video returning a FilePathResult, and when trying to play back in the browser, I'm seeing some frustrating issues, regardless of my using video.js or mediaelement.js.
- Chrome doesn't let you change the position using progressbar, nor does it allow you to replay the video once it has completed
- IE9 seems relatively fine
- Firefox doesn't show the elapsed/remaining time correctly
However, if I just give a relative path to the file being hosted, it all works fine. The videos need to be available only to users who belong to certain roles, so that isn't really an option.
The Action:
[Authorize]
public ActionResult Video(string fileName)
{
var pathBase = Server.MapPath("~/Downloads/Videos/");
var filePath = pathBase + fileName;
var contentType = ContentType(fileName);
return new FilePathResult(filePath, contentType) { FileDownloadName = fileName };
}
The Razor:
<!-- @t = the video entity -->
<video width="640" height="360" id="@t.Id" poster="@Url.Action("Video", "Download", new { fileName = @t.Poster })" controls="controls" preload="none">
<!-- MP4 source must come first for iOS -->
<source src="@Url.Action("Video", "Download", new { fileName = @t.Mp4 })" type='video/mp4' />
<!-- WebM for Firefox 4 and Opera -->
<source src="@Url.Action("Video", "Download", new { fileName = @t.WebM })" type='video/webm' />
<!-- OGG for Firefox 3 -->
<source src="@Url.Action("Video", "Download", new { fileName = @t.Ogv })" type='video/ogg' />
<!-- Fallback flash player for no-HTML5 browsers with JavaScript turned off -->
<object width="640" height="360" type="application/x-shockwave-flash" data="@Url.Content("~/Content/flashmediaelement.swf")">
<param name="movie" value="@Url.Content("~/Content/flashmediaelement.swf")" />
<param name="flashvars" value="controls=true&poster=@Url.Action("Video", "Download", new { fileName = @t.Poster })&file=@Url.Action("Video", "Download", new { fileName = @t.Mp4 })" />
<!-- Image fall back for non-HTML5 browser with JavaScript turned off and no Flash player installed -->
<img src="@Url.Action("Video", "Download", new { fileName = @t.Poster })" width="640" height="360" alt="@t.Title"
title="No video playback capabilities" />
</object>
</video>
Thanks for your answer!
I used something similar:
I ended up writing an HTTP Handler to deal with these extensions, though it seems Chrome's issue is to do with my handler not supporting Range requests.
I used the following blog post to help me out: http://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/. The solution (modified by me to include content type, as well as some basic security) is as follows: