我是MVC的新手,我正在尝试播放一个视频,它存储在我的数据库(SQL)中的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>
出现以下跳跃点但不起作用:
答案 0 :(得分: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);
}