代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
播放视频音频
作者:
dezai
/ 发布于
2014/2/20
/
446
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> /// Summary description for playmedia /// </summary> public class playmedia { public playmedia() { // // TODO: Add constructor logic here // } 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 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(); } } //部分格式没有添加在内 //------------------------------------------------------------------------------------------------------------------------------- 在论坛上找到的类,比较好用 playmedia pcplay = new playmedia(); playMediaLabel.Text = pcplay.Play("xxx.wmv", 450, 360); /* 程序控制媒体播放器,可控制宽度和高度 输入参数:媒体文件,帧宽度,帧高度 用法:Label_MediaPlayer.Text = PlayMedia(MediaFile, Width, Height) */ public string PlayMedia(string MediaFile , int FrameWidth,int FrameHeight) { string Str; Str = "<object Id='nstv' codeBase='"; Str += "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab"; Str += "#Version=5,1,52,701' type='application/x-oleobject' "; Str += "height='"; Str += FrameHeight; Str += "' stanDby='Loading Microsoft Windows Media Player components...' "; Str += "Width='"; Str += FrameWidth; Str += "' align='mIddle' "; Str += "classid='CLSId:22d6f312-b0f6-11d0-94ab-0080c74c7e95' "; Str += "VIEWASTEXT>"; Str += "<PARAM NAME='AudioStream' VALUE='-1'>"; Str += "<PARAM NAME='AutoSize' VALUE='1'>"; Str += "<PARAM NAME='AutoStart' VALUE='-1'>"; Str += "<PARAM NAME='AnimationAtStart' VALUE='-1'>"; Str += "<PARAM NAME='AllowScan' VALUE='-1'>"; Str += "<PARAM NAME='AllowChangeDisplaySize' VALUE='1'>"; Str += "<PARAM NAME='AutoRewind' VALUE='0'>"; Str += "<PARAM NAME='Balance' VALUE='0'>"; Str += "<PARAM NAME='BaseURL' VALUE=''>"; Str += "<PARAM NAME='BufferingTime' VALUE='5'>"; Str += "<PARAM NAME='CaptioningId' VALUE=''>"; Str += "<PARAM NAME='ClickToPlay' VALUE='-1'>"; Str += "<PARAM NAME='CursorType' VALUE='0'>"; Str += "<PARAM NAME='CurrentPosition' VALUE='-1'>"; Str += "<PARAM NAME='CurrentMarker' VALUE='0'>"; Str += "<PARAM NAME='defaultFrame' VALUE=''>"; Str += "<PARAM NAME='DisplayBackColor' VALUE='0'>"; Str += "<PARAM NAME='DisplayForeColor' VALUE='16777215'>"; Str += "<PARAM NAME='DisplayMode' VALUE='0'>"; Str += "<PARAM NAME='DisplaySize' VALUE='0'>"; Str += "<PARAM NAME='Enabled' VALUE='-1'>"; Str += "<PARAM NAME='EnableContextMenu' VALUE='true'>"; Str += "<PARAM NAME='EnablePositionControls' VALUE='-1'>"; Str += "<PARAM NAME='EnableFullScreenControls' VALUE='1'>"; Str += "<PARAM NAME='EnableTracker' VALUE='-1'>"; Str += "<PARAM NAME='Filename' VALUE='"; Str += MediaFile; Str += "'>"; Str += "<PARAM NAME='InvokeURLs' VALUE='-1'>"; Str += "<PARAM NAME='Language' VALUE='-1'>"; Str += "<PARAM NAME='Mute' VALUE='0'>"; Str += "<PARAM NAME='PlayCount' VALUE='1'>"; Str += "<PARAM NAME='PreviewMode' VALUE='0'>"; Str += "<PARAM NAME='Rate' VALUE='1'>"; Str += "<PARAM NAME='SAMILang' VALUE=''>"; Str += "<PARAM NAME='SAMIStyle' VALUE=''>"; Str += "<PARAM NAME='SAMifileName' VALUE=''>"; Str += "<PARAM NAME='SelectionStart' VALUE='-1'>"; Str += "<PARAM NAME='Selection} //' VALUE='-1'>"; Str += "<PARAM NAME='S} //OpenStateChangeEvents' VALUE='-1'>"; Str += "<PARAM NAME='S} //WarningEvents' VALUE='-1'>"; Str += "<PARAM NAME='S} //ErrorEvents' VALUE='-1'>"; Str += "<PARAM NAME='S} //KeyboardEvents' VALUE='0'>"; Str += "<PARAM NAME='S} //MouseClickEvents' VALUE='0'>"; Str += "<PARAM NAME='S} //MouseMoveEvents' VALUE='0'>"; Str += "<PARAM NAME='S} //PlayStateChangeEvents' VALUE='-1'>"; Str += "<PARAM NAME='ShowCaptioning' VALUE='0'>"; Str += "<PARAM NAME='ShowControls' VALUE='-1'>"; Str += "<PARAM NAME='ShowAudioControls' VALUE='-1'>"; Str += "<PARAM NAME='ShowDisplay' VALUE='0'>"; Str += "<PARAM NAME='ShowGotoBar' VALUE='0'>"; Str += "<PARAM NAME='ShowPositionControls' VALUE='-1'>"; Str += "<PARAM NAME='ShowStatusBar' VALUE='-1'>"; Str += "<PARAM NAME='ShowTracker' VALUE='-1'>"; Str += "<PARAM NAME='TransparentAtStart' VALUE='0'>"; Str += "<PARAM NAME='VIdeoBorderWidth' VALUE='0'>"; Str += "<PARAM NAME='VIdeoBorderColor' VALUE='0'>"; Str += "<PARAM NAME='VIdeoBorder3D' VALUE='0'>"; Str += "<PARAM NAME='Volume' VALUE='-600'>"; Str += "<PARAM NAME='WindowlessVIdeo' VALUE='0'>"; Str += "</object>"; return Str; }
试试其它关键字
播放视频音频
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
dezai
贡献的其它代码
(
1065
)
.
双色球
.
列出所有物理网络适配器
.
快乐数的 Python 实现
.
计算当月还剩天数
.
猜属相
.
二十四小时时钟
.
每日一语
.
很酷的日历
.
超长日历表单
.
最简单的时钟
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3