2017-04-07 55 views
0

我正在使用此库here,我正在使用此插件here播放视频。ASP.NET MVC中的范围请求 - 无法使用Google浏览器和Opera播放

按照代码:

控制器:

[HttpGet] 
public ActionResult StreamUploadedVideo() 
{    
    byte[] test = null; 

    using (var ctx = new Entities()) 
    { 
     var result = ctx.Table.Where(x => x.Field == 4).FirstOrDefault(); 

     test = result.Movie; 

     return new RangeFileContentResult(test, "video/mp4", "Name.mp4", DateTime.Now); 
    } 
} 

查看:

<video id="my-video" class="video-js" controls preload="auto" width="640" height="264" poster="MY_VIDEO_POSTER.jpg" data-setup="{}"> 
    <source src="@Url.Action("StreamUploadedVideo","Controller")" type='video/mp4'> 
    <p class="vjs-no-js"> 
     To view this video please enable JavaScript, and consider upgrading to a web browser that 
     <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> 
    </p> 
</video> 

问题:当我改变视频的时间(例如:更改时间从1:00到10:00分钟),我面临这个问题如下:

谷歌浏览器:A network error caused the media download to fail part-way.

歌剧:The media playback was aborted due to corruption problem or because the used features your browser did not support.

图片:

inserir a descrição da imagem aqui

浏览器的其余部分都很好。谷歌和Opera是今天的日期的最新更新版本:2017年7月4日

  • Micrososft边缘 - 好吧

  • 火狐 - 好吧

  • 的Internet Explorer - 好吧

  • 歌剧 - 错误

  • Google - 错误

任何解决方案?

回答

1

您的代码存在问题,因为您正在使用DateTime.Now代替modificationDate,该代码用于生成ETagLast-Modified标头。由于铬(铬和歌剧背后的引擎)范围请求可以是有条件的(这意味着它们可以包含If-Match/If-None-Match/If-Modified-Since/If-Unmodified-Since),因此导致产生412 Precondition Failed而不是200 OK206 Partial Content。如果底层内容没有改变,你应该使用相同的日期,就像这样。

[HttpGet] 
public ActionResult StreamUploadedVideo() 
{ 
    byte[] test = null; 
    DateTime lastModificationDate = DateTime.MinValue; 

    using (var ctx = new Entities()) 
    { 
     var result = ctx.Table.Where(x => x.Field == 4).FirstOrDefault(); 

     test = result.Movie; 
     lastModificationDate = result.LastModificationDate; 
    } 

    return new RangeFileContentResult(test, "video/mp4", "Name.mp4", lastModificationDate); 
} 
+0

Tank you tpeczek –

相关问题