如何在asp.net中如何在线播放各类视频文件

一。后台拼字符串动态加载写法

前台调用代码




    视频播放


   


   

   

     


       
     
   
    

   

   


后台调用代码

protected void Page_Load(object sender, EventArgs e)
    {
        this.video_content.InnerHtml = PlayMedia.Play("http://hot.tudou.com/flv/005/680/205/5680205.flv", 472,385);
      }

视频播放类:

using System;
using System.Collections.Generic;
using System.Text;

namespace Common
{
    public class PlayMedia
    {
        public PlayMedia()
        {
            //   
            //   TOD   在此处添加构造函数逻辑   
            //   
        }
        public static 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(".flv"))
            {
                return flv(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 "视频文件数据错误";
            }
        }
        ///  

   
        ///   flv格式文件播放   
        ///  
   
        ///      
        ///      
        private static string flv(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("             sb.Append("classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
            sb.Append(" height=\"" + height + "\"   width=\"" + width + "\"   >");
            sb.Append("");
            sb.Append("");           
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");

            return sb.ToString();
        }        
           

        ///  

   
        ///   wmv格式文件播放   
        ///  
   
        ///      
        ///      

        private static string wmv(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("             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("\n");
            sb.Append("");
            //   
            sb.Append("");
            sb.Append("");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("\n");
            sb.Append("
\n");
            return sb.ToString();
        }

        private static string wma(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            //sb.Append("");   
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");

            sb.Append("");

            return sb.ToString();

        }
        ///  

   
        ///   avi格式文件播放   
        ///  
   
        ///      
        ///      
        private static string avi(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");

            return sb.ToString();
        }

        private static string mpg(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");

            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");

            return sb.ToString();
        }

        private static string rm(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("");
            sb.Append("");
            //sb.Append("");   
            //sb.Append("");   
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            //sb.Append("");   
            sb.Append("");

            return sb.ToString();
        }

        private static string swf(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();


            sb.Append("             sb.Append("   height=\"" + height + "\"   width=\"" + width + "\"   >");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append(""); sb.Append("");
            sb.Append("");

            return sb.ToString();
        }

        private static string mp3(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("");

            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");
            sb.Append("");

            sb.Append("");
            return sb.ToString();

        }

        private static string img(string url, int width, int height)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("");
            return sb.ToString();
        }
    }
}



二。前台拼字符串JS调用写法

FLV需要播放器,其它视频格式直接插入相应的代码即可。 
------------------------------------- 
/**    
*参数说明  
u - 媒体URL  
w - 媒体宽度width  
h - 媒体高度height  
*/  

//播放Mediaplayer格式的视频,包括.avi .mpg .mpeg .wmv .wma .asf .mid .mp3等  
function pv_m(u, w, h){  
var pv='';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
document.write(pv);  
}  

//播放Realplay格式的视频,包括.rm .ram .rmvb等  
function pv_r(u, w, h){  
var pv='';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
document.write(pv);  
}  

//播放Quicktime格式的视频,包括.mov .amr .3gp等  
function pv_q(u, w, h){  
var pv='';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
pv += '';  
document.write(pv);  
}

你可能感兴趣的:(ASP.NET)