asp.net – .net MVC将MP4流式传输到iDevice问题
我一直在努力为视频提供一段代码,我遇到了一些问题.代码如下:
public ResumingFileStreamResult GetMP4Video(string videoID) { if (User.Identity.IsAuthenticated) { string clipLocation = string.Format("{0}Completed{1}.mp4",ConfigurationManager.AppSettings["VideoLocation"].ToString(),videoID); FileStream fs = new FileStream(clipLocation,FileMode.Open,FileAccess.Read); ResumingFileStreamResult fsr = new ResumingFileStreamResult(fs,"video/mp4"); return fsr; } else { return null; } } 这是我的HTML代码: <video controls preload poster="@Url.Content(string.Format("~/Videos/{0}_2.jpg",Model.VideoID))"> <source src="@Url.Action("GetMP4Video","Video",new { videoID = Model.VideoID })" type="video/mp4" /> <source src="@Url.Action("GetWebMVideo",new { videoID = Model.VideoID })" type="video/webm" /> <object id="flowplayer" data="@Url.Content("~/Scripts/FlowPlayer/flowplayer-3.2.14.swf")" type="application/x-shockwave-flash" width="640" height="360"> <param name="movie" value="@Url.Content("~/Scripts/FlowPlayer/flowplayer-3.2.14.swf")" /> <param name="allowfullscreen" value="true" /> <param name="flashvars" value="config={'playlist':['@Url.Content(string.Format("~/Videos/{0}_2.jpg",Model.VideoID))',{'url':'@Url.Action("GetMP4Video",new { videoID = Model.VideoID })','autoPlay':false}]}" /> </object> </video> 我的问题是这个设置似乎在我桌面的所有浏览器中都能正常工作,但是当我尝试使用我的iPad或iPhone加载页面时,它只显示播放图标,其中有一条线表示它无法播放.我尝试将mp4视频的源代码更改为mp4视频的直接链接,并立即开始播放它. 是否有一些我需要做的特别的事情,我错过了命令让我的方法与iDevices兼容?任何有关这方面的帮助将不胜感激. 解决方法
要使您的视频在iOS设备上播放,您需要实现对字节范围(或部分)请求的支持.这些类型的请求不允许下载整个内容,而是部分地下载块(典型的流).这是iOS设备在页面上获取和播放视频的唯一方式.
部分请求使用Range标头告诉服务器下一个块位置和大小.另一方面的服务器响应206部分内容和请求的块内容. 您可以找到ASP.NET处理程序的几个实现,它们可以处理Internet中的部分请求.我建议使用StaticFileHandler:易于安装,并且还具有开箱即用的缓存功能.它也可以通过Nuget提供,但该包名为Talifun.Web. 要配置StaticFileHandler,请在web.config中为mp4文件注册处理程序,并在单独的配置部分中对其进行配置: <configuration> <configSections> <section name="StaticFileHandler" type="Talifun.Web.StaticFile.Config.StaticFileHandlerSection,Talifun.Web" requirePermission="false" allowDefinition="MachineToApplication"/> </configSections> <StaticFileHandler webServerType="NotSet"> <!-- The defaults to use when an extension is found that does not have a specific rule --> <fileExtensionDefault name="Default" serveFromMemory="true" maxMemorySize="100000" compress="true"/> <!-- Specific rules for extension types --> <fileExtensions> <fileExtension name="VideoStaticContent" extension="3gp,3g2,asf,avi,dv,flv,mov,mp4,mpg,mpeg,wmv" serveFromMemory="true" maxMemorySize="100000" compress="false"/> </fileExtensions> </StaticFileHandler> <system.webServer> <handlers> <add name="StaticContentHandler" verb="GET,HEAD" path="*.mp4" type="Talifun.Web.StaticFile.StaticFileHandler,Talifun.Web"/> </handlers> </system.webServer> </configuration> 如果还可以通过创建ASP.NET处理程序并直接调用StaticFileManager来轻松应用自定义逻辑,例如授权或自定义视频文件源. public class MyOwnVideoHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { // Authorization or any other stuff. ... // Get file from your storage. FileInfo file = ...; // Serve the file with StaticFileHandler. StaticFileManager.Instance.ProcessRequest(new HttpContextWrapper(context),file); } } 另外,您可以查看Scott Mitchell’s article about partial requests以获取详细信息并使用其作者编写的处理程序:它对我有用,但它没有缓存功能. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc-3 – 实体框架4.1代码优先,需要延迟加载引用在
- asp.net-mvc – xVal和ASP.Net MVC 2 AddModelStateErrors问
- DevExpress ASP.NET示例资源最全分享!(一)
- .net – 如何将变量传递给SqlDataSource的SelectCommand?
- ASP.Net / C#:替换数据绑定字段中的字符
- 校园邮政快递查询系统基于B/S模式下的asp系统
- asp.net-mvc-4 – 在MVC4文件中上传其在DB中保存的“System
- asp.net-mvc – 使用ASP.NET MVC的IIS应用程序请求路由(ARR
- 如何在ASP.NET中混合WebForms和MVC
- asp.net-mvc-3 – 偶数和奇数表行与Razor
- asp.net-mvc – 使用Entity Framework在控制器中
- asp.net – Moq Parent没有默认构造函数.必须显式
- asp.net – IIS需要很长时间才能首次运行
- asp.net – 登录后重定向到上一页
- asp.net-mvc – 使用List的奇怪剃刀行为
- ASP.NET MVC:如何为LDAP身份验证设置web.config
- asp.net – 无法CoCreate Profiler错误 – 但不使
- Asp.net调用C#层调用Managed C调用Native C
- asp.net – 如何以完全信任的方式部署IIS ASP .N
- asp.net – Application_Start在工作站上工作正常