网页播放器代码 至少支持8种格式

using System; 
 using System.Collections.Generic; 
 using System.Linq; 
 using System.Text; 
  
 namespace Common.Player 
 { 
     public class VideoPlayer 
     { 
         ///  <summary> 
         /// 生成视频播放器的HTML源码 
         ///  </summary> 
         ///  <remarks> 
         /// 调用方法 <div> <%=playHtml %> </div> 
         ///  </remarks> 
         ///  <param name="strUrl">视频存放路径 </param> 
         ///  <param name="strWidth">播放器宽度 </param> 
         ///  <param name="strHeight">播放器高度 </param> 
         ///  <returns> </returns> 
         public static string GetPlayHtml(string strUrl, string strWidth, string strHeight) 
         { 
             string resultHtml = ""; 
             if (strUrl != "") 
             { 
                 string Exts = "avi,wmv,asf,mov,rm,ra,ram"; 
                 string isExt = ""; 
                 if (strUrl != "") 
                 { 
                     isExt = strUrl.Substring(strUrl.LastIndexOf(".") + 1);//获取后缀名  
                 } 
                 if (!Exts.Contains(isExt)) 
                 { 
                     resultHtml = "非法视频文件"; 
                 } 
                 else 
                 { 
                     switch (isExt) 
                     { 
                         case "avi": 
                         case "wmv": 
                         case "asf": 
                         case "mov": 
                             resultHtml += " <EMBED id=MediaPlayer src=" + strUrl + " width=" + strWidth + " height=" + strHeight + " loop='false' autostart='true'> </EMBED>"; 
                             break; 
                         //case "mov": 
                         case "rm": 
                         case "ra": 
                         case "ram": 
                             resultHtml += " <OBJECT height=" + strHeight + " width=" + strWidth + " classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA>"; 
                             break; 
                     } 
                     resultHtml += " <PARAM NAME='_ExtentX' VALUE='12700'>"; 
                     resultHtml += " <PARAM NAME='_ExtentY' VALUE='9525'>"; 
                     resultHtml += " <PARAM NAME='AUTOSTART' VALUE='-1'>";//VALUE='-1' 
                     resultHtml += " <PARAM NAME='SHUFFLE' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='PREFETCH' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='NOLABELS' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='SRC' VALUE='" + strUrl + "'>"; 
                     resultHtml += " <PARAM NAME='CONTROLS' VALUE='ImageWindow'>"; 
                     resultHtml += " <PARAM NAME='CONSOLE' VALUE='Clip'>"; 
                     resultHtml += " <PARAM NAME='LOOP' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='NUMLOOP' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='CENTER' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='MAINTAINASPECT' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='BACKGROUNDCOLOR' VALUE='#000000'>"; 
                     resultHtml += " </OBJECT>"; 
                     resultHtml += " <BR>"; 
                     resultHtml += " <OBJECT height=32 width=" + strWidth + " classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA>"; 
                     resultHtml += " <PARAM NAME='_ExtentX' VALUE='12700'>"; 
                     resultHtml += " <PARAM NAME='_ExtentY' VALUE='847'>"; 
                     resultHtml += " <PARAM NAME='AUTOSTART' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='SHUFFLE' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='PREFETCH' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='NOLABELS' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='CONTROLS' VALUE='ControlPanel,StatusBar'>"; 
                     resultHtml += " <PARAM NAME='CONSOLE' VALUE='Clip'>"; 
                     resultHtml += " <PARAM NAME='LOOP' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='NUMLOOP' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='CENTER' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='MAINTAINASPECT' VALUE='0'>"; 
                     resultHtml += " <PARAM NAME='BACKGROUNDCOLOR' VALUE='#000000'>"; 
                     resultHtml += " </OBJECT>"; 
                 } 
             } 
             return resultHtml; 
         } 
     } 
 } 


前台直接绑定后回的脚本就可以了<%=html%>
至少支持8种常见的格式
posted @ 2011-09-29 17:46  清风333  阅读(508)  评论(0)    收藏  举报