我想在asp.net中進行漸進式視頻流式傳輸。我已經寫了一個代碼,但仍然沒有正確加載。有沒有關於它的想法。asp.net中視頻的漸進式流式傳輸
請看看我的代碼或建議我最好的方法來做到這一點。我不希望播放器等待下載整個視頻,然後開始播放。我想現在就開始玩。
以下是我的代碼。
string path = "Test.mp4";
string rootpath = Server.MapPath(Request.ApplicationPath);
string file = string.Format(@"{0}\\{1}", rootpath, path);
if (File.Exists(file) && file.Contains("mp4"))
{
FileStream filestream = new FileStream(file, FileMode.Open, FileAccess.Read);
long length = filestream.Length;
Response.AppendHeader("Content-Type", "video/mp4");
Response.AddHeader("Content-Disposition", "attachment; filename=" + path + "");
Response.AppendHeader("Content-Length", length.ToString());
const int buffersize = 16384;
byte[] buffer = new byte[buffersize];
int count = filestream.Read(buffer, 0, buffersize);
while (count > 0)
{
if (!Response.IsClientConnected)
count = -1;
else
{
Response.OutputStream.Write(buffer, 0, count);
Response.Flush();
count = filestream.Read(buffer, 0, buffersize);
}
}
}
此致 Jalpesh