欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 视频播放类

程序员文章站 2022-07-22 09:08:47
复制代码 代码如下:using system; using system.data; using system.configuration; using system.we...
复制代码 代码如下:

using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
/// <summary>
/// playclass 的摘要说明
/// </summary>
namespace configtools
{
/// <summary>
/// playclass 的摘要说明。
///原作csdn,经本人稍加修改
/// </summary>
public class playclass
{
public playclass()
{
//
// tod 在此处添加构造函数逻辑
//
}
public 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(".jpg")||strtmp.endswith(".gif"))
{
return img(url,width, height);
}
else if(strtmp.endswith(".rm"))
{
return rm(url,width, height);
}
else
{
return "数据错误";
}
}
/// <summary>
/// wmv格式文件播放
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private string wmv(string url, int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<object id=\"wmplay\" style=\"width: "+width+"px;height:"+height+"px\" \n");
sb.append("classid=\"clsid:6bf52a52-394a-11d3-b153-00c04f79faa6\" type=application/x-oleobject standby=\"loading windows media player components...\"");
sb.append("codebase=\"downloads/mediaplayer9.0_cn.exe\" viewastext>\n");
sb.append("<param name=\"url\" value='"+url+"'>\n");
sb.append("<param name=\"controls\" value=\"controlpanel,statusba\">");
//<param name="controls" value="controlpanel,statusbar">
sb.append("<param name=\"hidden\" value=\"1\">");
sb.append("<param name=\"showcontrols\" value=\"0\">");
sb.append("<param name=\"rate\" value=\"1\">\n");
sb.append("<param name=\"balance\" value=\"0\">\n");
sb.append("<param name=\"currentposition\" value=\"-1\">\n");
sb.append("<param name=\"defaultframe\" value=\"\">\n");
sb.append("<param name=\"playcount\" value=\"100\">\n");
sb.append("<param name=\"autostart\" value=\"-1\">\n");
sb.append("<param name=\"currentmarker\" value=\"0\">\n");
sb.append("<param name=\"invokeurls\" value=\"-1\">\n");
sb.append("<param name=\"baseurl\" value=\"\">\n");
sb.append("<param name=\"volume\" value=\"85\">\n");
sb.append("<param name=\"mute\" value=\"0\">\n");
sb.append("<param name=\"uimode\" value=\"mini\">\n");
sb.append("<param name=\"stretchtofit\" value=\"0\">\n");
sb.append("<param name=\"windowlessvideo\" value=\"0\">\n");
sb.append("<param name=\"enabled\" value=\"-1\">\n");
sb.append("<param name=\"enablecontextmenu\" value=\"false\">\n");
sb.append("<param name=\"fullscreen\" value=\"0\">\n");
sb.append("<param name=\"samistyle\" value=\"\">\n");
sb.append("<param name=\"samilang\" value=\"\">\n");
sb.append("<param name=\"samifilename\" value=\"\">\n");
sb.append("<param name=\"captioningid\" value=\"\">\n");
sb.append("</object><br>\n");
return sb.tostring();
}
private string wma(string url,int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<object id=\"wmplay\" classid=\"clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" style=\"z-index: 101; left: 40px; width: 240px; position: absolute; top: 32px; height: 248px\" >");
sb.append("<param name=\"filename\" value=\""+url+"\">");
sb.append("<param name=\"playcount\" value=\"1\">");
sb.append("<param name=\"autostart\" value=\"0\">");
sb.append("<param name=\"clicktoplay\" value=\"1\">");
//sb.append("<param name=\"displaysize\" value=\"0\">");
sb.append("<param name=\"enablefullscreen controls\" value=\"1\">");
sb.append("<param name=\"showaudio controls\" value=\"1\">");
sb.append("<param name=\"enablecontext menu\" value=\"1\">");
sb.append("<param name=\"showdisplay\" value=\"1\">");
sb.append("</object>");
return sb.tostring();
}
/// <summary>
/// avi格式文件播放
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private string avi(string url,int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<object id=\"wmplay\" width=\"400\" height=\"200\" border=\"0\" classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\">");
sb.append("<param name=\"showdisplay\" value=\"0\">");
sb.append("<param name=\"showcontrols\" value=\"1\">");
sb.append("<param name=\"autostart\" value=\"1\">");
sb.append("<param name=\"autorewind\" value=\"0\">");
sb.append("<param name=\"playcount\" value=\"0\">");
sb.append("<param name=\"appearance value=\"0 value=\"\"\">");
sb.append("<param name=\"borderstyle value=\"0 value=\"\"\">");
sb.append("<param name=\"moviewindowheight\" value=\"240\">");
sb.append("<param name=\"moviewindowwidth\" value=\"320\">");
sb.append("<param name=\"filename\" value=\""+url+"\">");
sb.append("</object>");
return sb.tostring();
}
private string mpg(string url, int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<object classid=\"clsid:05589fa1-c356-11ce-bf01-00aa0055595a\" id=\"wmplay\" width=\"239\" height=\"250\">");
sb.append("<param name=\"filename\" value=\"" + url + "\" valuetype=\"ref\">");
sb.append("<param name=\"appearance\" value=\"0\">");
sb.append("<param name=\"autostart\" value=\"-1\">");
sb.append("<param name=\"allowchangedisplaymode\" value=\"-1\">");
sb.append("<param name=\"allowhidedisplay\" value=\"0\">");
sb.append("<param name=\"allowhidecontrols\" value=\"-1\">");
sb.append("<param name=\"autorewind\" value=\"-1\">");
sb.append("<param name=\"balance\" value=\"0\">");
sb.append("<param name=\"currentposition\" value=\"0\">");
sb.append("<param name=\"displaybackcolor\" value=\"0\">");
sb.append("<param name=\"displayforecolor\" value=\"16777215\">");
sb.append("<param name=\"displaymode\" value=\"0\">");
sb.append("<param name=\"enabled\" value=\"-1\">");
sb.append("<param name=\"enablecontextmenu\" value=\"-1\">");
sb.append("<param name=\"enablepositioncontrols\" value=\"-1\">");
sb.append("<param name=\"enableselectioncontrols\" value=\"0\">");
sb.append("<param name=\"enabletracker\" value=\"-1\">");
sb.append("<param name=\"fullscreenmode\" value=\"0\">");
sb.append("<param name=\"moviewindowsize\" value=\"0\">");
sb.append("<param name=\"playcount\" value=\"1\">");
sb.append("<param name=\"rate\" value=\"1\">");
sb.append("<param name=\"selectionstart\" value=\"-1\">");
sb.append("<param name=\"selectionend\" value=\"-1\">");
sb.append("<param name=\"showcontrols\" value=\"-1\">");
sb.append("<param name=\"showdisplay\" value=\"-1\">");
sb.append("<param name=\"showpositioncontrols\" value=\"0\">");
sb.append("<param name=\"showtracker\" value=\"-1\">");
sb.append("<param name=\"volume\" value=\"-480\">");
sb.append("</object>");
return sb.tostring();
}
private string rm(string url, int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<object id=\"wmplay\" codebase=\"downloads/realplayer10-5gold_cn0302.exe\" classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" height=" + height + " width=" + width + ">");
sb.append("<param name=\"src\" value=\"" + url + "\">");
//sb.append("<param name=\"_extentx\" value=\"9313\">");
//sb.append("<param name=\"_extenty\" value=\"7620\">");
sb.append("<param name=\"autostart\" value=\"0\">");
sb.append("<param name=\"shuffle\" value=\"0\">");
sb.append("<param name=\"prefetch\" value=\"0\">");
sb.append("<param name=\"nolabels\" value=\"0\">");
sb.append("<param name=\"controls\" value=\"imagewindow,controlpanel,statusbar\">");
sb.append("<param name=\"console\" value=\"clip1\">");
sb.append("<param name=\"loop\" value=\"0\">");
sb.append("<param name=\"numloop\" value=\"0\">");
sb.append("<param name=\"center\" value=\"0\">");
sb.append("<param name=\"maintainaspect\" value=\"0\">");
sb.append("<param name=\"backgroundcolor\" value=\"#000000\">");
//sb.append("<embed src type=\"audio/x-pn-realaudio-plugin\" console=\"clip1\" controls=\"imagewindow\" height=\"250\" width=\"354\" autostart=\"false\">");
sb.append("</object>");
return sb.tostring();
}
private string swf(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=6,0,29,0\" ");
sb.append(" height=\"" + height + "\" width=\"" + width + "\" >");
sb.append("<param name=\"flashvars\" value=\"\">");
sb.append("<param name=\"movie\" value=\"" + url + "\">");
sb.append("<param name=\"src\" value=\"" + url + "\">");
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("<embed src=\"" + url + "\" 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();
}
private string mp3(string url, int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<object classid=\"wmplay\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,4,5,715\" type=\"application/x-oleobject\" width=\" + width + \" height=\" + height + \" hspace=\"0\" standby=\"loading microsoft windows media player components...\" id=\"nsplay\">");
sb.append("<param name=\"autorewind\" value=\"0\">");
sb.append("<param name=\"filename\" value=\" + url + \">");
sb.append("<param name=\"showcontrols\" value=\"1\">");
sb.append("<param name=\"showpositioncontrols\" value=\"0\">");
sb.append("<param name=\"showaudiocontrols\" value=\"1\">");
sb.append("<param name=\"showtracker\" value=\"0\">");
sb.append("<param name=\"showdisplay\" value=\"0\">");
sb.append("<param name=\"showstatusbar\" value=\"1\">");
sb.append("<param name=\"showgotobar\" value=\"0\">");
sb.append("<param name=\"showcaptioning\" value=\"0\">");
sb.append("<param name=\"autostart\" value=\"1\">");
sb.append("<param name=\"volume\" value=\"-2500\">");
sb.append("<param name=\"animationatstart\" value=\"0\">");
sb.append("<param name=\"transparentatstart\" value=\"0\">");
sb.append("<param name=\"allowchangedisplaysize\" value=\"0\">");
sb.append("<param name=\"allowscan\" value=\"0\">");
sb.append("<param name=\"enablecontextmenu\" value=\"0\">");
sb.append("<param name=\"clicktoplay\" value=\"0\">");
sb.append("</object>");
return sb.tostring();
}
private string img(string url, int width, int height)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("<img src=\"" + url + "\" height=\"" + height + "\" width=\"" + width + "\" border=\"0\">");
return sb.tostring();
}
}
}