2016-09-16 4 views
0

私はMVCで新しく、ビデオ(VARBINARY(max)フィールドにデータベースに格納されている)を再生しようとしています。私はすでにWEBアプリケーションにビデオを表示することができますが、問題はプログレバーです。それは私が別のポイントへのジャンプを実行すると動作しますが動作しません。私はこれについていくつかの資料を読みましたが、私はそれを解決することができません。問題はバッファリング(開始/終了)に関するものだと思う。以下は私のコードです。ジャンピングポイントブルーが動作しない - ビデオ

コントローラー:

public ActionResult Media(int id) 
{ 
    byte[] teste = null; 
    string query1 = "SELECT * FROM Movie WHERE ID = '"+id+"'"; 
    using (SqlConnection connection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) 
    using (SqlCommand command1 = new SqlCommand(query1, connection1)) 
    { 
     connection1.Open(); 
     var reader = command1.ExecuteReader(); 

     if (reader.HasRows) 
     { 
      reader.Read(); 
      teste = (byte[])reader["Movie"]; 
     } 
     connection1.Close(); 
    } 
    var memoryStream = new MemoryStream(teste); 
    return new FileStreamResult(memoryStream, Convert.ToString(teste)); 

} 

ビュー:以下

<video width="400" controls> 
     <source src="@Url.Action("Media","Account",new { id = 3 })" type="video/mp4"> 
    </video> 

ジャンプポイントが表示されますが、動作しません:

enter image description here

答えて

0

http://forums.asp.net/t/2065545.aspx?HTML5+Audio+Seek+bar+doesn+t+work

public ActionResult Media(string id) 
    { 
     byte[] teste = null; 
     string query1 = "SELECT * FROM Movie WHERE ID = '"+id+"'"; 
     using (SqlConnection connection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) 
     using (SqlCommand command1 = new SqlCommand(query1, connection1)) 
     { 
      connection1.Open(); 
      var reader = command1.ExecuteReader(); 

      if (reader.HasRows) 
      { 
      reader.Read(); 
      teste = (byte[])reader["Movie"]; 
      } 
      connection1.Close(); 
     } 
     long fSize = teste.Length; 
     long startbyte = 0; 
     long endbyte = fSize - 1; 
     int statusCode = 200; 
     if ((Request.Headers["Range"] != null)) 
     { 
      //Get the actual byte range from the range header string, and set the starting byte. 
      string[] range = Request.Headers["Range"].Split(new char[] { '=', '-' }); 
      startbyte = Convert.ToInt64(range[1]); 
      if (range.Length > 2 && range[2] != "") endbyte = Convert.ToInt64(range[2]); 
      //If the start byte is not equal to zero, that means the user is requesting partial content. 
      if (startbyte != 0 || endbyte != fSize - 1 || range.Length > 2 && range[2] == "") 
      { statusCode = 206; }//Set the status code of the response to 206 (Partial Content) and add a content range header.          
     } 
     long desSize = endbyte - startbyte + 1; 
     //Headers 
     Response.StatusCode = statusCode; 
     Response.ContentType = "video/mp4"; 
     Response.AddHeader("Content-Accept", Response.ContentType); 
     Response.AddHeader("Content-Length", desSize.ToString()); 
     Response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}", startbyte, endbyte, fSize)); 


     var fs = new MemoryStream(teste,(int)startbyte, (int)desSize); 
     return new FileStreamResult(fs, userFile.FileType); 
    } 
+0

タンクします!それは完璧に働いた。 –

関連する問題