2017-04-07 51 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 –

相關問題