2012-07-31 73 views
2

我有兩種方法,第一種返回視頻文件,另一種返回縮略圖圖像。.NET MVC - 爲jPlayer返回視頻文件

public ActionResult Video(string id) 
    { 
     UserVideo videoEntity = AccountBasicEntity.GetUserVideoWithID(id); 

     string videoPath = ConfigurationManager.AppSettings["VideoPath"] + videoEntity.VideoFileName; 


     return File(videoPath, "video/mp4"); 
    } 

    public ActionResult Thumb(string id) 
    { 
     UserVideo videoEntity = AccountBasicEntity.GetUserVideoWithID(id); 

     string thumbPath = ConfigurationManager.AppSettings["ThumbsPath"] + videoEntity.PreviewImageFileName; 

     return File(thumbPath, "image/jpg"); 
    } 

,我可以爲

http://localhost/media/video/GTt-b2DcEG (returns video file) 
http://localhost/media/thumb/GTt-b2DcEG (returns image file) 

到達網址的方法,工作正常,返回的圖像文件。但另一個不起作用,瀏覽器(chrome)不播放或jPlayer不播放視頻文件但瀏覽器或jplayer顯示縮略圖圖像。我調試和路徑都可以。

視頻路徑是:C:\網絡\數據\視頻\ GTT-b2DcEG.mp4 映像路徑是:C:\網絡\數據\大拇指\ GTT-b2DcEG.jpg

難道我錯過了什麼?在這種情況下提供基於ajax的視頻播放器的最佳方式是什麼?

謝謝。

客戶端:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset=utf-8 /> 

<!-- Website Design By: www.happyworm.com --> 
<title>Demo : jPlayer as a video player</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<link href="skin/pink.flag/jplayer.pink.flag.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> 
<script type="text/javascript" src="js/jquery.jplayer.min.js"></script> 
<script type="text/javascript"> 
//<![CDATA[ 
$(document).ready(function(){ 

    $("#jquery_jplayer_1").jPlayer({ 
     ready: function() { 
      $(this).jPlayer("setMedia", { 
       m4v: "http://localhost/media/video/GTt-b2DcEG", 
       poster: "http://localhost/media/thumb/GTt-b2DcEG" 
      }); 
     }, 
     swfPath: "js", 
     supplied: "webmv, ogv, m4v", 
     size: { 
      width: "640px", 
      height: "360px", 
      cssClass: "jp-video-360p" 
     } 
    }); 

}); 
//]]> 
</script> 
</head> 
<body> 
     <div id="jp_container_1" class="jp-video jp-video-360p"> 
      <div class="jp-type-single"> 
       <div id="jquery_jplayer_1" class="jp-jplayer"></div> 
       <div class="jp-gui"> 
        <div class="jp-video-play"> 
         <a href="javascript:;" class="jp-video-play-icon" tabindex="1">play</a> 
        </div> 
        <div class="jp-interface"> 
         <div class="jp-progress"> 
          <div class="jp-seek-bar"> 
           <div class="jp-play-bar"></div> 
          </div> 
         </div> 
         <div class="jp-current-time"></div> 
         <div class="jp-duration"></div> 
         <div class="jp-title"> 
          <ul> 
           <li>Big Buck Bunny Trailer</li> 
          </ul> 
         </div> 
         <div class="jp-controls-holder"> 
          <ul class="jp-controls"> 
           <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li> 
           <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li> 
           <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li> 
           <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li> 
           <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li> 
           <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li> 
          </ul> 
          <div class="jp-volume-bar"> 
           <div class="jp-volume-bar-value"></div> 
          </div> 

          <ul class="jp-toggles"> 
           <li><a href="javascript:;" class="jp-full-screen" tabindex="1" title="full screen">full screen</a></li> 
           <li><a href="javascript:;" class="jp-restore-screen" tabindex="1" title="restore screen">restore screen</a></li> 
           <li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li> 
           <li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li> 
          </ul> 
         </div> 
        </div> 
       </div> 
       <div class="jp-no-solution"> 
        <span>Update Required</span> 
        To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>. 
       </div> 
      </div> 
     </div> 
</body> 

</html> 
+0

你需要證明你是如何消耗在客戶端的視頻。 – casperOne 2012-07-31 19:33:09

+0

我使用jPlayer並將視頻網址設置爲http:// localhost/media/video/GTt-b2DcEG,如果我將視頻網址設置爲文件網址(http://localhost/sample.mp4),它可以工作。 – Can 2012-08-01 19:10:00

+0

我的意思是在客戶端的代碼。 – casperOne 2012-08-01 19:35:51

回答

1

你沒有提到你已經做了什麼故障排除。

當我以前遇到過這個問題時,我檢查的第一件事就是你在IIS中添加了MIME類型。默認情況下,IIS 6 & 7不會爲未配置的MIME類型提供內容。

How to add mime types with IIS7 Web.config

下一步將是用於編碼的MP4的編解碼器是由jPlayer播放。

jPlayer Media Encoding

+0

我已經爲mp4添加了MIME類型(視頻/ mp4)。問題是MVC不會返回mp4視頻文件,當我使用「return File(path,mimetype)」時什麼也不返回。 – Can 2012-08-01 20:37:52