昨天看到利用FMS(Flash Media Server)做在线视频录制的资料,地址:http://www.cincn.com/article.asp?id=15,还有播放流式FLV文件的资料,地址:http://blogs.ugidotnet.org/kfra/archive/2006/10/04/50003.aspx,很好,把我高兴坏了,所以有了FMS架设视频服务器的想法, ,主要内容如下:
开发步骤:
1。下载FMS http://blogs.ugidotnet.org/kfra/archive/2006/10/04/50003.aspx,安装配置。
2。使用flash制作FMS视频采集的控件。
3。aspx页面嵌入FMS采集控件,运行采集数据上传到FMS服务器,修改数据库的视频文件存放地址。
4。页面嵌入Flash播放控件,加入FLV处理流代码:
\n
using System;
using System.IO;
using System.Web;
/**//// <summary>
/// Summary description for FLVStreaming
/// </summary>
public class FLVStreaming : IHttpHandler
{
private static readonly byte[] _flvheader = HexToByte(“464C5601010000000900000009″); //”FLV\\x1\\x1\\x9\\x9″
\n
public FLVStreaming()
{
}
\n
public void ProcessRequest(HttpContext context)
{
try
{
int pos;
int length;
\n
// Check start parameter if present
string filename = Path.GetFileName(context.Request.FilePath);
\n
using (FileStream fs = new FileStream(context.Server.MapPath(filename), FileMode.Open, FileAccess.Read, FileShare.Read))
{
string qs = context.Request.Params["start"];
\n
if (string.IsNullOrEmpty(qs))
{
pos = 0;
length = Convert.ToInt32(fs.Length);
}
else
{
pos = Convert.ToInt32(qs);
length = Convert.ToInt32(fs.Length – pos) + _flvheader.Length;
}
\n
// Add HTTP header stuff: cache, content type and length
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(DateTime.Now);
\n
context.Response.AppendHeader(“Content-Type”, “video/x-flv”);
context.Response.AppendHeader(“Content-Length”, length.ToString());
\n
// Append FLV header when sending partial file
if (pos > 0)
{
context.Response.OutputStream.Write(_flvheader, 0, _flvheader.Length);
fs.Position = pos;
}
\n
// Read buffer and write stream to the response stream
const int buffersize = 16384;
byte[] buffer = new byte[buffersize];
int count = fs.Read(buffer, 0, buffersize);
while (count > 0)
{
if (context.Response.IsClientConnected)
{
context.Response.OutputStream.Write(buffer, 0, count);
count = fs.Read(buffer, 0, buffersize);
}
else
{
count = -1;
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
\n
public bool IsReusable
{
get { return true; }
}
\n
private static byte[] HexToByte(string hexString)
{
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
\n
}
修改配置文件,运行页面即可调出视频,播放速度很不错。虽说轻描淡写但已经给出应用Asp.net开发视频网站的思路。如果有兴趣可以联系我。
来源:http://www.cnblogs.com/xiucai/archive/2007/06/13/782001.html