前台控件:
<table >
<tr>
<td>
<div id="video_content" runat="server" style=""></div>
</td>
</tr>
</table>
后台:
using BizLogic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Page.ProjectFile
{
public partial class FLVViewer : System.Web.UI.Page
{
public static string strAttPath = System.Web.HttpContext.Current.Server.MapPath("~/TempFile/");
public static string attachGuid = "";
public string FileURL
{
get;
set;
}
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["attachGuid"] != null)
{
attachGuid = Request.QueryString["attachGuid"].ToString();
FileURL = CreateAttachImage(
System.Web.HttpContext.Current.Server.MapPath("~/"),
attachGuid,
Request.QueryString["AttachConName"],
false, false);
this.video_content.InnerHtml = Play(FileURL, 1500, 700); //FileURL
}
}
public string CreateAttachImage(string iisAppPath, string attachGuid, string attachConName, bool blnAddWaterMark, bool blnAddZuoFeiWM)
{
string strReturnPath = "";
string AttachFileName = "AttachInfo";
string strImageFileName = "";//图片的文件名称
string strFullFilePath = "";//生成图片的路径,返回值
try
{
//生成到IIS程序下的临时文件夹
FileStream objFileStream;
BinaryWriter objBinaryWriter;
//MapPath一定要把EpointMisTempFile写进去,兼容文件服务器模式
if (!Directory.Exists(strAttPath + attachGuid))
{
Directory.CreateDirectory(strAttPath + attachGuid);
}
string conAttachStorage = System.Configuration.ConfigurationManager.ConnectionStrings["RongGuangMis_ConnectionString"].ConnectionString;
//查询附件内容
CommonDataRow oRow = new CommonDataRow("Frame_AttachInfo", "RowGuid", attachGuid, conAttachStorage);
if (oRow.R_HasFilled)
{
strImageFileName = Convert.ToString(oRow["AttachFileName"]);
strFullFilePath = strAttPath + attachGuid + "/" + strImageFileName;
objFileStream = new FileStream(strFullFilePath, FileMode.OpenOrCreate, FileAccess.Write);
objBinaryWriter = new BinaryWriter(objFileStream);
objBinaryWriter.Write((byte[])oRow[AttachFileName]);
objBinaryWriter.Close();
objFileStream.Close();
}
//IIS程式中的路径目录。
strReturnPath = Request.ApplicationPath + "/TempFile/" + attachGuid + "/" + strImageFileName.Substring(0, strImageFileName.LastIndexOf(".")) + ".flv";
}
catch (Exception err)
{
//to-do
}
//返回图片路径
return strReturnPath;
}
public static string Play(string url, int width, int height)
{
string strTmp = url.ToLower();
if (strTmp.EndsWith(".flv"))
{
return flv(url, width, height);
}
else
{
return "视频文件数据错误";
}
}
private static string flv(string url, int width, int height)
{
// 路径样式:http://localhost/xiangmu/....
string SwfUrl = "HTTP://"+HttpContext.Current.Request.Url.Host + System.Web.HttpContext.Current.Request.ApplicationPath.ToString() + "/Page/ProjectFile/";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<object codeBase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,22,87\" ");
sb.Append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
sb.Append(" height=\"" + height + "\" width=\"" + width + "\" >");
sb.Append("<param name=\"FlashVars\" value=\"vcastr_file=" + url + "&LogoText=&BufferTime=3\">");
sb.Append("<param name=\"Movie\" value=\"" + SwfUrl + "Flvplayer.swf\">");
sb.Append("<param name=\"allowFullScreen\" value=\"true\">");
sb.Append("<param name=\"WMode\" value=\"Window\">");
sb.Append("<param name=\"Play\" value=\"1\">");
sb.Append("<param name=\"Loop\" value=\"-1\">");
sb.Append("<param name=\"Quality\" value=\"High\">");
sb.Append("<param name=\"SAlign\" value=\"\">");
sb.Append("<param name=\"Menu\" value=\"0\">");
sb.Append("<param name=\"Base\" value=\"\">");
sb.Append("<param name=\"AllowScriptAccess\" value=\"always\">");
sb.Append("<param name=\"Scale\" value=\"ShowAll\">");
sb.Append("<param name=\"DeviceFont\" value=\"0\">");
sb.Append("<param name=\"EmbedMovie\" value=\"0\">");
sb.Append("<param name=\"BGColor\" value=\"\">");
sb.Append("<param name=\"SWRemote\" value=\"\">");
sb.Append("<param name=\"MovieData\" value=\"\">");
sb.Append("<param name=\"SeamlessTabbing\" value=\"1\">");
sb.Append("<param name=\"Profile\" value=\"0\">");
sb.Append("<param name=\"ProfileAddress\" value=\"\">");
sb.Append("<param name=\"ProfilePort\" value=\"0\">");
sb.Append("<embed src=\"" + SwfUrl + "FLVPlayer_Progressive.swf\" flashvars=\"vcastr_file=" + url + "&LogoText=\" height=\"" + height + "\" width=\"" + width + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" menu=\"false\">");
sb.Append("</embed>");
sb.Append("</object>");
return sb.ToString();
}
}
}
项目中应添加两个播放器插件
具体见百度云 文件夹 flv格式播放功能 。