播放原理:
- MP4文件是使用jwplayer进行播放的。
- FLV文件用的是vcastr22.swf播放的。
- MP3这个比较简单,用jwplayer,跟player.swf都可以。
- SWF就是flash的基本格式,无压力。
- RM/AVI用的是windows的WMPLAYER。
相关播放器文件在文章末尾提供下载地址。
代码展示
public string Play(string url, int width, int height) { string strTmp = url.ToLower(); if (strTmp.EndsWith(".wmv") || strTmp.EndsWith(".wma") || strTmp.EndsWith(".avi") || strTmp.EndsWith(".asf") || strTmp.EndsWith(".mpg") || strTmp.EndsWith(".wav") || strTmp.EndsWith(".mid") || strTmp.EndsWith(".asf") || strTmp.EndsWith(".wm")) { return wmv(url, width, height); } else if (strTmp.EndsWith(".mp3")) { // return mp4(url, width, height); return mp3(url, width, height); } else if (strTmp.EndsWith(".swf")) { return swf(url, width, height); } else if (strTmp.EndsWith(".rm")) { return rm(url, width, height); } else if (strTmp.EndsWith(".rmvb")) { return rmvb(url, width, height); } else if (strTmp.EndsWith(".flv")) { return mp4(url, width, height); } else if (strTmp.EndsWith(".mp4")) { return mp4(url, width, height); } else { return "数据错误"; } } private string mp4(string _File, int _Width, int _Height) { return string.Format(@"加载中...", "{", _File, _Height, _Width, "}"); } private string flv(string _File, int _Width, int _Height) { string texts = string.Empty; string config = "1:自动播放|0:连续播放|100:默认音量|0:控制栏位置|2:控制栏显示|0x000033:主体颜色|60:主体透明度|0x66ff00:光晕颜色|0xffffff:图标颜色|0xffffff:文字颜色|:logo文字|:logo地址|:结束swf地址"; string swffile = "/Flv/vcastr22.swf"; return @""; } ////// wmv格式文件播放 /// /// ///private string wmv(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("
n"); return sb.ToString(); } private string rmvb(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(""); sb.Append("
"); sb.Append(""); return sb.ToString(); } private string wma(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(""); return sb.ToString(); } ////// avi格式文件播放 /// /// ///private string avi(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(""); return sb.ToString(); } private string mpg(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(""); return sb.ToString(); } private string rm(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(""); return sb.ToString(); } private string swf(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(""); return sb.ToString(); } private string mp3(string url, int width, int height) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendFormat(@" ", height, width, url); return sb.ToString(); }
代码&文件下载
http://pan.baidu.com/s/1KlhI 压缩包中包含(jwplayer、vcastr22.swf、player.swf 与演示代码)