ASP.NET MVC 中的范围请求 - 无法使用 Google 浏览器和 Opera

Range Request in ASP.NET MVC - Failed to play with Google browser and Opera

我正在使用这个库 here and I'm using this plugin here 来播放视频。

关注代码:

控制器:

[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 分钟),我遇到以下问题:

Google Chrome: 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.

图片:

其余的浏览器都很好。 Google 和 Opera 是今天日期的最新更新版本:07/04/2017

有什么解决办法吗?

您的代码存在问题,因为您将 DateTime.Now 用于 modificationDate,用于生成 ETagLast-Modified headers。由于 chromium(Chrome 和 opera 背后的引擎)范围请求可以是有条件的(这意味着它们可以包含 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);
}