c#版本视频在线播放(通用播放器调用),支持avi,wmv,asf,mov,rm,ra,ram等

来源:互联网 发布:康熙怒斥群臣知乎 编辑:程序博客网 时间:2024/04/30 14:24

产品页用户提交视频播放文件时,如何根据提交的网址内的视频格式进行正确的播放. 参考"阿里西西"作者的文章(网页视频播放器程序代码(通用代码),支持avi,wmv,asf,mov,rm,ra,ram等 ),整理了一下c#版本的通用代码.

定义方法

private void SelPlay(string strUrl,int strWidth, int StrHeight)
  {
   string Exts = string.Empty;
   string isExt = string.Empty;

   if (strUrl != "")
   {
    isExt = strUrl.Substring(strUrl.LastIndexOf('.')+1).ToLower();
   }
   else
   {
    isExt = "";
   }

   Exts = "avi,wmv,asf,mov,rm,ra,ram";
   if (Exts.IndexOf("isExt") >= -1)
   {
    switch(isExt)
    {
     case "avi":  
     case "wmv":     
     case "asf":     
     case "mov":
      this.Response.Write("<EMBED id=MediaPlayer src="+strUrl+" width="+strWidth+"  height="+StrHeight+" loop=false autostart=true ></EMBED>");
      break;     
     case "rm":
     case "ra":
     case "ram":
      Response.Write ("<OBJECT height="+StrHeight+" width="+strWidth+" classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA>");
      Response.Write ("<PARAM NAME=_ExtentX VALUE=12700>");
      Response.Write( "<PARAM NAME=_ExtentY VALUE=9525>");
      Response.Write ("<PARAM NAME=AUTOSTART VALUE=-1>");
      Response.Write( "<PARAM NAME=SHUFFLE VALUE=0>");
      Response.Write ("<PARAM NAME=PREFETCH VALUE=0>");
      Response.Write ("<PARAM NAME=NOLABELS VALUE=0>");
       Response.Write ("<PARAM NAME=SRC VALUE="+strUrl+">");
      Response.Write( "<PARAM NAME=CONTROLS VALUE=ImageWindow>");
      Response.Write( "<PARAM NAME=CONSOLE VALUE=Clip>");
      Response.Write( "<PARAM NAME=LOOP VALUE=0>");
      Response.Write( "<PARAM NAME=NUMLOOP VALUE=0>");
      Response.Write( "<PARAM NAME=CENTER VALUE=0>");
      Response.Write( "<PARAM NAME=MAINTAINASPECT VALUE=0>");
      Response.Write( "<PARAM NAME=BACKGROUNDCOLOR VALUE=#000000>");
      Response.Write ("</OBJECT>");
      Response.Write ("<BR>");
      Response.Write ("<OBJECT height=32 width="+strWidth+" classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA>");
      Response.Write( "<PARAM NAME=_ExtentX VALUE=12700>");
      Response.Write( "<PARAM NAME=_ExtentY VALUE=847>");
      Response.Write( "<PARAM NAME=AUTOSTART VALUE=0>");
      Response.Write( "<PARAM NAME=SHUFFLE VALUE=0>");
      Response.Write( "<PARAM NAME=PREFETCH VALUE=0>");
      Response.Write( "<PARAM NAME=NOLABELS VALUE=0>");
      Response.Write( "<PARAM NAME=CONTROLS VALUE=ControlPanel,StatusBar>");
      Response.Write( "<PARAM NAME=CONSOLE VALUE=Clip>");
      Response.Write( "<PARAM NAME=LOOP VALUE=0>");
      Response.Write( "<PARAM NAME=NUMLOOP VALUE=0>");
      Response.Write( "<PARAM NAME=CENTER VALUE=0>");
      Response.Write( "<PARAM NAME=MAINTAINASPECT VALUE=0>");
      Response.Write( "<PARAM NAME=BACKGROUNDCOLOR VALUE=#000000>");
      Response.Write( "</OBJECT>");
      break;
    }
   }
    else
   {                                                                                                                                                                                                                                     
    this.Response.Write("非法视频文件");
   }   
  }
  

调用方式:

       public string url;
        protected void Page_Load(object sender, EventArgs e)
        {
          if(!IsPostBack)
            {
       try
               {
                url = Request.QueryString["url"].ToString();                
               }
              catch
               {
                 url = "1.wmv";
               }
              SelPlay(Url,280,220);
             }
        }
   

原创粉丝点击