【发布时间】:2012-08-07 00:14:20
【问题描述】:
我正在提供来自 MVC3 站点的视频,返回视频的控制器操作返回 FilePathResult,当我尝试在浏览器中播放时,我看到了一些令人沮丧的问题,无论我使用的是 video.js或 mediaelement.js。
- Chrome 不允许您使用进度条更改位置,也不允许您在视频完成后重播视频
- IE9 好像还不错
- Firefox 无法正确显示经过/剩余时间
但是,如果我只是提供托管文件的相对路径,则一切正常。 这些视频只需要对属于特定角色的用户开放,所以这不是一个真正的选择。
行动:
[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 };
}
剃刀:
<!-- @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>
【问题讨论】:
-
完全解析后的 URL 是什么样的?
-
下载/视频?fileName=file.ext
标签: asp.net-mvc-3 html5-video mediaelement.js http-streaming video.js