| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 728 人关注过本帖, 2 人收藏
标题:网络播放文件控制类 (恋雪怜冰 进)
取消只看楼主 加入收藏
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
结帖率:93.75%
收藏(2)
 问题点数:0 回复次数:0 
网络播放文件控制类 (恋雪怜冰 进)
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace WebTest
{
    /// <summary>
    /// C#中的媒体播放控制类
    /// </summary>
    public class PlayerController
    {
        public PlayerController()
        {
            //   
            //   TOD   在此处添加构造函数逻辑   
            //   
        }
        /// <summary>
        /// 播放文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        public string PlayFile(string url, int width, int height)
        {
            string srtResult = "数据错误";

            string strTmp = url.ToLower();
            int lastPointIndex = strTmp.LastIndexOf(".");

            if (lastPointIndex != -1)
            {
                string fileExt = strTmp.Substring(lastPointIndex, strTmp.Length - lastPointIndex);

                switch (fileExt)
                {
                    case ".wmv":
                    case ".asf":
                        srtResult = PlayWmv(url, width, height);
                        break;

                    case ".wma":
                        srtResult = PlayWma(url, width, height);
                        break;

                    case ".avi":
                        srtResult = PlayAvi(url, width, height);
                        break;

                    case ".mpg":
                        srtResult = PlayMpg(url, width, height);
                        break;

                    case ".rm":
                        srtResult = PlayRm(url, width, height);
                        break;

                    case ".swf":
                        srtResult = PlaySwf(url, width, height);
                        break;

                    case ".mp3":
                        srtResult = PlayMp3(url, width, height);
                        break;

                    case ".jpg":
                    case ".jpeg":
                    case ".gif":
                        srtResult = PlayImg(url, width, height);
                        break;

                }   //end switch (strTmp)
            }   //end if (lastPointIndex != -1)

            return srtResult;
        }

        /// <summary>
        ///  播放wmv格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlayWmv(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<object   id=\"WMPlay\"   style=\"WIDTH:   " + width + "px;height:" + height + "px\"   \n");
            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("<param   name=\"URL\"   value='" + url + "'>\n");
            sb.Append("<param   name=\"controls\"   value=\"ControlPanel,StatusBa\">");
            sb.Append("<param   name=\"hidden\"   value=\"1\">");
            sb.Append("<param   name=\"ShowControls\"   VALUE=\"0\">");
            sb.Append("<param   name=\"rate\"   value=\"1\">\n");
            sb.Append("<param   name=\"balance\"   value=\"0\">\n");
            sb.Append("<param   name=\"currentPosition\"   value=\"-1\">\n");
            sb.Append("<param   name=\"defaultFrame\"   value=\"\">\n");
            sb.Append("<param   name=\"playCount\"   value=\"100\">\n");
            sb.Append("<param   name=\"autoStart\"   value=\"-1\">\n");
            sb.Append("<param   name=\"currentMarker\"   value=\"0\">\n");
            sb.Append("<param   name=\"invokeURLs\"   value=\"-1\">\n");
            sb.Append("<param   name=\"baseURL\"   value=\"\">\n");
            sb.Append("<param   name=\"volume\"   value=\"85\">\n");
            sb.Append("<param   name=\"mute\"   value=\"0\">\n");
            sb.Append("<param   name=\"uiMode\"   value=\"mini\">\n");
            sb.Append("<param   name=\"stretchToFit\"   value=\"0\">\n");
            sb.Append("<param   name=\"windowlessVideo\"   value=\"0\">\n");
            sb.Append("<param   name=\"enabled\"   value=\"-1\">\n");
            sb.Append("<param   name=\"enableContextMenu\"   value=\"false\">\n");
            sb.Append("<param   name=\"fullScreen\"   value=\"0\">\n");
            sb.Append("<param   name=\"SAMIStyle\"   value=\"\">\n");
            sb.Append("<param   name=\"SAMILang\"   value=\"\">\n");
            sb.Append("<param   name=\"SAMIFilename\"   value=\"\">\n");
            sb.Append("<param   name=\"captioningID\"   value=\"\">\n");
            sb.Append("</object><br>\n");

            return sb.ToString();
        }

        /// <summary>
        ///  播放wma格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlayWma(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<object   id=\"WMPlay\"   classid=\"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95\"   style=\"Z-INDEX:   101;   LEFT:   40px;   WIDTH:   240px;   POSITION:   absolute;   TOP:   32px;   HEIGHT:   248px\"   >");
            sb.Append("<param   name=\"Filename\"   value=\"" + url + "\">");
            sb.Append("<param   name=\"PlayCount\"   value=\"1\">");
            sb.Append("<param   name=\"AutoStart\"   value=\"0\">");
            sb.Append("<param   name=\"ClickToPlay\"   value=\"1\">");
            sb.Append("<param   name=\"EnableFullScreen   Controls\"   value=\"1\">");
            sb.Append("<param   name=\"ShowAudio   Controls\"   value=\"1\">");
            sb.Append("<param   name=\"EnableContext   Menu\"   value=\"1\">");
            sb.Append("<param   name=\"ShowDisplay\"   value=\"1\">");
            sb.Append("</object>");

            return sb.ToString();

        }

        /// <summary>
        ///  播放avi格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>   
        private string PlayAvi(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<object   id=\"WMPlay\"   width=\"400\"   height=\"200\"   border=\"0\"   classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\">");
            sb.Append("<param   name=\"ShowDisplay\"   value=\"0\">");
            sb.Append("<param   name=\"ShowControls\"   value=\"1\">");
            sb.Append("<param   name=\"AutoStart\"   value=\"1\">");
            sb.Append("<param   name=\"AutoRewind\"   value=\"0\">");
            sb.Append("<param   name=\"PlayCount\"   value=\"0\">");
            sb.Append("<param   name=\"Appearance   value=\"0   value=\"\"\">");
            sb.Append("<param   name=\"BorderStyle   value=\"0   value=\"\"\">");
            sb.Append("<param   name=\"MovieWindowHeight\"   value=\"240\">");
            sb.Append("<param   name=\"MovieWindowWidth\"   value=\"320\">");
            sb.Append("<param   name=\"FileName\"   value=\"" + url + "\">");
            sb.Append("</object>");

            return sb.ToString();
        }

        /// <summary>
        ///  播放mpg格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlayMpg(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<object   classid=\"clsid:05589FA1-C356-11CE-BF01-00AA0055595A\"   id=\"WMPlay\"   width=\"239\"   height=\"250\">");
            sb.Append("<param   name=\"Filename\"   value=\"" + url + "\"   valuetype=\"ref\">");
            sb.Append("<param   name=\"Appearance\"   value=\"0\">");
            sb.Append("<param   name=\"AutoStart\"   value=\"-1\">");
            sb.Append("<param   name=\"AllowChangeDisplayMode\"   value=\"-1\">");
            sb.Append("<param   name=\"AllowHideDisplay\"   value=\"0\">");
            sb.Append("<param   name=\"AllowHideControls\"   value=\"-1\">");
            sb.Append("<param   name=\"AutoRewind\"   value=\"-1\">");
            sb.Append("<param   name=\"Balance\"   value=\"0\">");
            sb.Append("<param   name=\"CurrentPosition\"   value=\"0\">");
            sb.Append("<param   name=\"DisplayBackColor\"   value=\"0\">");
            sb.Append("<param   name=\"DisplayForeColor\"   value=\"16777215\">");
            sb.Append("<param   name=\"DisplayMode\"   value=\"0\">");
            sb.Append("<param   name=\"Enabled\"   value=\"-1\">");
            sb.Append("<param   name=\"EnableContextMenu\"   value=\"-1\">");
            sb.Append("<param   name=\"EnablePositionControls\"   value=\"-1\">");
            sb.Append("<param   name=\"EnableSelectionControls\"   value=\"0\">");
            sb.Append("<param   name=\"EnableTracker\"   value=\"-1\">");
            sb.Append("<param   name=\"FullScreenMode\"   value=\"0\">");
            sb.Append("<param   name=\"MovieWindowSize\"   value=\"0\">");
            sb.Append("<param   name=\"PlayCount\"   value=\"1\">");
            sb.Append("<param   name=\"Rate\"   value=\"1\">");
            sb.Append("<param   name=\"SelectionStart\"   value=\"-1\">");
            sb.Append("<param   name=\"SelectionEnd\"   value=\"-1\">");
            sb.Append("<param   name=\"ShowControls\"   value=\"-1\">");
            sb.Append("<param   name=\"ShowDisplay\"   value=\"-1\">");
            sb.Append("<param   name=\"ShowPositionControls\"   value=\"0\">");
            sb.Append("<param   name=\"ShowTracker\"   value=\"-1\">");
            sb.Append("<param   name=\"Volume\"   value=\"-480\">");
            sb.Append("</object>");

            return sb.ToString();
        }

        /// <summary>
        ///  播放rm格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlayRm(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<OBJECT   ID=\"WMPlay\"   codebase=\"downloads/RealPlayer10-5GOLD_cn0302.exe\"   CLASSID=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\"   HEIGHT=" + height + "   WIDTH=" + width + ">");
            sb.Append("<param   name=\"SRC\"   value=\"" + url + "\">");
            sb.Append("<param   name=\"AUTOSTART\"   value=\"0\">");
            sb.Append("<param   name=\"SHUFFLE\"   value=\"0\">");
            sb.Append("<param   name=\"PREFETCH\"   value=\"0\">");
            sb.Append("<param   name=\"NOLABELS\"   value=\"0\">");
            sb.Append("<param   name=\"CONTROLS\"   value=\"ImageWindow,ControlPanel,statusbar\">");
            sb.Append("<param   name=\"CONSOLE\"   value=\"Clip1\">");
            sb.Append("<param   name=\"LOOP\"   value=\"0\">");
            sb.Append("<param   name=\"NUMLOOP\"   value=\"0\">");
            sb.Append("<param   name=\"CENTER\"   value=\"0\">");
            sb.Append("<param   name=\"MAINTAINASPECT\"   value=\"0\">");
            sb.Append("<param   name=\"BACKGROUNDCOLOR\"   value=\"#000000\">");
            sb.Append("</OBJECT>");

            return sb.ToString();
        }

        /// <summary>
        ///  播放swf格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlaySwf(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<OBJECT   codeBase=\"http://download.,0,29,0\"   ");
            sb.Append("   height=\"" + height + "\"   width=\"" + width + "\"   >");
            sb.Append("<PARAM   NAME=\"FlashVars\"   VALUE=\"\">");
            sb.Append("<PARAM   NAME=\"Movie\"   VALUE=\"" + url + "\">");
            sb.Append("<PARAM   NAME=\"Src\"   VALUE=\"" + url + "\">");
            sb.Append("<PARAM   NAME=\"WMode\"   VALUE=\"Window\">");
            sb.Append("<PARAM   NAME=\"Play\"   VALUE=\"-1\">");
            sb.Append("<PARAM   NAME=\"Loop\"   VALUE=\"-1\">");
            sb.Append("<PARAM   NAME=\"Quality\"   VALUE=\"High\">");
            sb.Append("<PARAM   NAME=\"SAlign\"   VALUE=\"\">");
            sb.Append("<PARAM   NAME=\"Menu\"   VALUE=\"0\">");
            sb.Append("<PARAM   NAME=\"Base\"   VALUE=\"\">");
            sb.Append("<PARAM   NAME=\"AllowScriptAccess\"   VALUE=\"always\">");
            sb.Append("<PARAM   NAME=\"Scale\"   VALUE=\"ShowAll\">");
            sb.Append("<PARAM   NAME=\"DeviceFont\"   VALUE=\"0\">");
            sb.Append("<PARAM   NAME=\"EmbedMovie\"   VALUE=\"0\">");
            sb.Append("<PARAM   NAME=\"BGColor\"   VALUE=\"\">");
            sb.Append("<PARAM   NAME=\"SWRemote\"   VALUE=\"\">");
            sb.Append("<PARAM   NAME=\"MovieData\"   VALUE=\"\">");
            sb.Append("<PARAM   NAME=\"SeamlessTabbing\"   VALUE=\"1\">");
            sb.Append("<embed   src=\"" + url + "\"   height=\"" + height + "\"   width=\"" + width + "\"   quality=\"high\"   pluginspage=\"http://www.\"type=\"application/x-shockwave-flash\"   menu=\"false\">"); sb.Append("</embed>");
            sb.Append("</OBJECT>");

            return sb.ToString();
        }

        /// <summary>
        ///  播放mp3格式文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlayMp3(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<object   classid=\"WMPlay\"   codebase=\"http://activex.,4,5,715\"   type=\"application/x-oleobject\"   width=\"   +   width   +   \"   height=\"   +   height   +   \"   hspace=\"0\"   standby=\"Loading   Microsoft   Windows   Media   Player   components...\"   id=\"NSPlay\">");
            sb.Append("<param   name=\"AutoRewind\"   value=\"0\">");
            sb.Append("<param   name=\"FileName\"   value=\"   +   url   +   \">");
            sb.Append("<param   name=\"ShowControls\"   value=\"1\">");
            sb.Append("<param   name=\"ShowPositionControls\"   value=\"0\">");
            sb.Append("<param   name=\"ShowAudioControls\"   value=\"1\">");
            sb.Append("<param   name=\"ShowTracker\"   value=\"0\">");
            sb.Append("<param   name=\"ShowDisplay\"   value=\"0\">");
            sb.Append("<param   name=\"ShowStatusBar\"   value=\"1\">");
            sb.Append("<param   name=\"ShowGotoBar\"   value=\"0\">");
            sb.Append("<param   name=\"ShowCaptioning\"   value=\"0\">");
            sb.Append("<param   name=\"AutoStart\"   value=\"1\">");
            sb.Append("<param   name=\"Volume\"   value=\"-2500\">");
            sb.Append("<param   name=\"AnimationAtStart\"   value=\"0\">");
            sb.Append("<param   name=\"TransparentAtStart\"   value=\"0\">");
            sb.Append("<param   name=\"AllowChangeDisplaySize\"   value=\"0\">");
            sb.Append("<param   name=\"AllowScan\"   value=\"0\">");
            sb.Append("<param   name=\"EnableContextMenu\"   value=\"0\">");
            sb.Append("<param   name=\"ClickToPlay\"   value=\"0\">");
            sb.Append("</object>");
           
            return sb.ToString();

        }

        /// <summary>
        ///  播放image文件
        /// </summary>
        /// <param name="url">播放文件的路径</param>
        /// <param name="width">播放文件时所显示的宽度</param>
        /// <param name="height">播放文件时所显示的高度</param>
        /// <returns></returns>
        private string PlayImg(string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<img   src=\"" + url + "\"   height=\"" + height + "\"   width=\"" + width + "\"   border=\"0\">");
          
            return sb.ToString();
        }
    }
}

调用:
程序代码:
public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PlayerController pc = new PlayerController();
            string filePath = "http://minmeitt.";
            //string filePath = @"F:\others\SDCC Office daily body exercise.Wmv";
            Response.Write(pc.PlayFile(filePath, 480, 320));
        }
    }
网络路径与本地路径均可以。
搜索更多相关主题的帖子: 网络 文件 播放 
2010-09-28 13:56
快速回复:网络播放文件控制类 (恋雪怜冰 进)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054957 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved