asp.net网页播放器

之前要完成一个支持多支持多种格式的视频播放器,在网上找到一个VB写的,然后改成C#,近段在网上也见有不少人问这个问,在此分享

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;
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值