前台调用代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>视频播放</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><div id="video_content" runat="server" style=""></div> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台调用代码
protected void Page_Load(object sender, EventArgs e)
{
this.video_content.InnerHtml = PlayMedia.Play("http://136.154.22.100/CamelDirectShow/x.flv", 472, 385); }
视频播放类:
using System;
using System.Collections.Generic;
using System.Text;
namespace Common
{
public class PlayMedia
{
public PlayMedia()
{
//
// TOD 在此处添加构造函数逻辑
//
}
public static string Play(string url, int width, int height)
{
string strTmp = url.ToLower();
if (strTmp.EndsWith(".wmv") || strTmp.EndsWith(".mp3") || strTmp.EndsWith(".wma") || strTmp.EndsWith(".avi") || strTmp.EndsWith(".asf") || strTmp.EndsWith(".mpg"))
{
return wmv(url, width, height);
}
else if (strTmp.EndsWith(".mp3"))
{
return mp3(url, width, height);
}
else if (strTmp.EndsWith(".swf"))
{
return swf(url, width, height);
}
else if (strTmp.EndsWith(".flv"))
{
return flv(url, width, height);
}
else if (strTmp.EndsWith(".jpg") || strTmp.EndsWith(".gif"))
{
return img(url, width, height);
}
else if (strTmp.EndsWith(".rm"))
{
return rm(url, width, height);
}
else
{
return "视频文件数据错误";
}
}
/// <summary>
/// flv格式文件播放
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private static string flv(string url, int width, int height)
{
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=www.um173.com&BufferTime=3/">");
sb.Append("<param name=/"Movie/" value=/"http://136.154.22.100/CamelDirectShow/vcastr.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/">");