这是我的想法: 1. 将视频从免费托管到我的服务器(OK)示例:http://yanoshop.com/dms/xem/dms.aspx?url=http: //up.4share.vn/f/3103020403020003 /3830e2bfe4bdc4091f28a94d1fb9bf3d.webm.file 2. 然后将文件从服务器流式传输到客户端(在 FireFox 和 Chrome 上正常,但在 IE 上) 示例:http ://www.yanoshop.com/dms/xem/webm.aspx?u=http:// yanoshop.com/dms/xem/dms.aspx?url=http://up.4share.vn/f/3103020403020003/3830e2bfe4bdc4091f28a94d1fb9bf3d.webm.file
注意:我正在使用 HTML5 在移动设备上运行它(我正在使用 VideoJS 插件)
这是我使用的代码:
//Create a stream for the file
Stream stream = null;
//This controls how many bytes to read at a time and send to the client
int bytesToRead = 50000;
// Buffer to read bytes in chunk size specified above
byte[] buffer = new Byte[bytesToRead];
// The number of bytes read
try
{
//Create a WebRequest to get the file
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(downloadLink);
fileReq.Timeout = 99999;
//Create a response for this request
HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
if (fileReq.ContentLength > 0)
fileResp.ContentLength = fileReq.ContentLength;
//Get the Stream returned from the response
stream = fileResp.GetResponseStream();
// prepare the response to the client. resp is the client Response
Response.Clear();
Response.AddHeader("Pragma", "public");
Response.Expires = 0;
Response.AddHeader("Cache-Control", "no-cache, must-revalidate");
Response.AddHeader("Cache-Control", "public");
Response.AddHeader("Content-Description", "File Transfer");
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetLastModified(DateTime.Now);
//Indicate the type of data being sent
Response.ContentType = ExtentionToContentType(filename);
Response.AddHeader("Accept-Ranges", "bytes");
//Name the file
Response.AppendHeader("Content-Disposition", "filename=" + filename);
Response.AddHeader("Content-Length", fileResp.ContentLength.ToString());
//Response.AddHeader("Content-Encoding", "gzip");
//Response.AddHeader("Accept-Header", stream.Length.ToString());
int length;
int count = 0;
if (count == 0)
{
}
do
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read data into the buffer.
length = stream.Read(buffer, 0, bytesToRead);
// and write it out to the response's output stream
Response.OutputStream.Write(buffer, 0, length);
// Flush the data
Response.Flush();
//Clear the buffer
buffer = new Byte[bytesToRead];
}
else
{
// cancel the download if client has disconnected
length = -1;
}
} while (length > 0); //Repeat until no data is read
}
finally
{
if (stream != null)
{
//Close the input stream
stream.Close();
}
}