I have a simple MVC
action that returns a FilePathResult
pointing to a video. For some reason HTML5
video (using js-video.js
) is not playing the video. If I change the URL to a URL I know works, the video plays fine. So it must be to do with the way I serve the file.
我有一个简单的MVC动作,返回指向视频的FilePathResult。出于某种原因,HTML5视频(使用js-video.js)不播放视频。如果我将URL更改为我知道可用的URL,则视频播放正常。所以它必须与我提供文件的方式有关。
If I browse to the URL in the browser, the video downloads and then plays fine.
如果我浏览浏览器中的URL,视频会下载然后播放正常。
The video is .mp4
with a returned MIME type of video/mp4
.
视频为.mp4,返回的MIME类型为video / mp4。
I am using Video Studio 2012
, .NET 4
, IIS 8 Express
and Windows 7 x64 Home Premium
.
我正在使用Video Studio 2012,.NET 4,IIS 8 Express和Windows 7 x64 Home Premium。
Here is my respective code:
这是我的代码:
[Authorize(Roles = "File_Read")]
public FileResult Get(int? id)
{
try
{
if (id == null)
throw new ArgumentNullException("id");
var fileRepo = FileRepositoryFactory.Repository;
var file = fileRepo.GetById(id.Value);
if (file == null)
throw new InvalidOperationException(String.Format("Failed to find file with id: {0}", id));
if (String.IsNullOrWhiteSpace(file.FilePath))
{
return this.File(file.Data, file.MIMEType, file.FileName);
}
else
{
return this.File(file.FilePath, file.MIMEType, file.FileName);
}
}
catch (Exception ex)
{
return this.File("failed.txt", "text/plain");
}
}
Here is a screen shot of what Chrome
returns:
以下是Chrome返回内容的屏幕截图:
1 个解决方案
#1
6
The HTML5 Video
tage requires support for Range Requests.
HTML5视频广告需要支持范围请求。
In case of static file this support is provided internally by the server, but in case of ASP.NET MVC action it needs to be implemented at ActionResult
level.
对于静态文件,此支持由服务器在内部提供,但是在ASP.NET MVC操作的情况下,它需要在ActionResult级别实现。
The article Range Requests in ASP.NET MVC – RangeFileResult describes in details how to create an ASP.NET MVC ActionResult
with Range Request support. There is also a sample application which is using VideoJS available here: VideoJS in ASP.NET MVC
ASP.NET MVC中的Range Requests文章 - RangeFileResult详细描述了如何创建具有Range Request支持的ASP.NET MVC ActionResult。还有一个使用VideoJS的示例应用程序:ASP.NET MVC中的VideoJS
#1
6
The HTML5 Video
tage requires support for Range Requests.
HTML5视频广告需要支持范围请求。
In case of static file this support is provided internally by the server, but in case of ASP.NET MVC action it needs to be implemented at ActionResult
level.
对于静态文件,此支持由服务器在内部提供,但是在ASP.NET MVC操作的情况下,它需要在ActionResult级别实现。
The article Range Requests in ASP.NET MVC – RangeFileResult describes in details how to create an ASP.NET MVC ActionResult
with Range Request support. There is also a sample application which is using VideoJS available here: VideoJS in ASP.NET MVC
ASP.NET MVC中的Range Requests文章 - RangeFileResult详细描述了如何创建具有Range Request支持的ASP.NET MVC ActionResult。还有一个使用VideoJS的示例应用程序:ASP.NET MVC中的VideoJS