2016-09-16 2 views
0

Я новичок в MVC, и я пытаюсь воспроизвести видео, которое хранится в моей базе данных (SQL) в поле VARBINARY (max). Я уже могу показать видео в своем приложении WEB, но проблема в том, что это progres bar. Он появляется, но не работает, когда я выполняю прыжки в другую точку. Я прочитал некоторые материалы об этом, но я не могу его решить. Я думаю, что проблема связана с буферизацией (начало/конец). Ниже мой код.Jumping Point Blue Not Work - Video

Контроллер:

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> 

Точка Jumping ниже появляется, но не работает:

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

Tank you !!! Он работал идеально. –

 Смежные вопросы

  • Нет связанных вопросов^_^