如何使用媒体播放器控件在asp.net 3.5中播放视频 [英] How to use media player control to play videos in asp.net 3.5

查看:87
本文介绍了如何使用媒体播放器控件在asp.net 3.5中播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想创建一个可以在其中播放视频的Web项目.我只是无法运行代码.我不了解如何构建媒体播放器控件的逻辑.我已经完成了从站点获取的编码,但不了解在哪里调用这些方法或我必须要做的事情.我已经在类文件中编写了代码.我应该在哪里编写.我不了解RenderContents方法.正在发送代码段.请提供帮助.

Hi,
I want to create a web project in which I can play videos.i am just unable to run the code.i am not understanding the logic how to build mediaplayer control.i have done the coding that i am taking from a site but not understanding where to call these methods or what more i have to do.I have written the code in class file.where i should write this.i am not understanding RenderContents method.I am sending the code snippet.please help.

#region namespaces
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using System.Text;
#endregion
[DefaultProperty("MovieURL"), 
ToolboxData("<{0}:MediaPlayerActX runat=server>")]
//MediaPlayerActX is the name of my aspx form
    public partial class MediaPlayerActX : System.Web.UI.WebControls.WebControl  //here i have change the .page into .webcontrols.webcontrol   
 {
       #region Default Property Values
        const string DefaultMovieURL = "";
        const bool DefaultAutoStart = false;
        const int DefaultBalance = 0;
        const int DefaultCurrentPosition = 0;
        const bool DefaultEnableContextMenu = true;
        const bool DefaultFullScreen = false;
        const bool DefaultMute = false;
        const int DefaultPlayCount = 1;
        const System.Single DefaultRate = (float)1.0;
        const bool DefaultStretchToFit = false;
        const Enumerations.PlayerMode DefaultUIMode = Enumerations.PlayerMode.Full;
        const int DefaultVolume = -1;
        #endregion
        #region Constructor
        public MediaPlayerActX()
        {
            this.Width = System.Web.UI.WebControls.Unit.Pixel(320);
            this.Height = System.Web.UI.WebControls.Unit.Pixel(240);
        }
        #endregion
    #region Public properties
        
      [Bindable(true),Category("Settings"),Description("Absolute or relative URL to movie.")]
        public string MovieURL
        {
            get
            {
                if (ViewState["MovieURL"] == null)
                    return DefaultMovieURL;
                else
                    return (string)ViewState["MovieURL"];
            }
            set
            {
                if (value != DefaultMovieURL)
                    ViewState["MovieURL"] = value;
                else
                    ViewState["MovieURL"] = null;
            }
        }
      [Bindable(true), Category("Settings"), Description("Would movie play when page is loaded.")]
      public bool AutoStart
      {
          get
          {
              if (ViewState["AutoStart"] == null)
                  return DefaultAutoStart;
              else
                  return (bool)ViewState["AutoStart"];
          }
          set
          {
              if (value != DefaultAutoStart)
                  ViewState["AutoStart"] = value;
              else
                  ViewState["AutoStart"] = null;
          }
      }
      [Bindable(true), Category("Settings"), Description("Balance")]
      int Balance
      {
          get
          {
              if (ViewState["Balance"] == null)
                  return DefaultBalance;
              else
                  return (int)ViewState["Balance"];
          }
          set
          {
              if (value > 100)
                  value = 100;
              if (value < -100)
                  value = -100;
              if (value != DefaultBalance)
                  ViewState["Balance"] = value;
              else
                  ViewState["Balance"] = null;
          }
      }
      [Bindable(true), Category("Settings"), Description("Current postion.")]
      int CurrentPosition
      {
          get
          {
              if (ViewState["CurrentPosition"] == null)
                  return DefaultCurrentPosition;
              else
                  return (int)ViewState["CurrentPosition"];
          }
          set
          {
              if (value < 0)
                  value = 0;
              if (value != DefaultCurrentPosition)
                  ViewState["CurrentPosition"] = value;
              else
                  ViewState["CurrentPosition"] = null;
          }
      }
      [Bindable(true), Category("Settings")]
      bool EnableContextMenu
      {
          get
          {
              if (ViewState["EnableContextMenu"] == null)
                  return DefaultEnableContextMenu;
              else
                  return (bool)ViewState["EnableContextMenu"];
          }
          set
          {
              if (value != DefaultEnableContextMenu)
                  ViewState["EnablecontextMenu"] = value;
              else
                  ViewState["EnablecontextMenu"] = null;
          }
      }

      [Bindable(true), Category("Settings"), Description("Would movie be played in full screen.")]
      bool FullScreen
      {
          get
          {
              if (ViewState["FullScreen"] == null)
                  return DefaultFullScreen;
              else
                  return (bool)ViewState["FullScreen"];
          }
          set
          {
              if (value != DefaultFullScreen)
                  ViewState["FullScreen"] = value;
              else
                  ViewState["FullScreen"] = null;
          }
      }
      [Bindable(true), Category("Settings"), Description("Play video without sound.")]
      bool Mute
      {
          get
          {
              if (ViewState["Mute"] == null)
                  return DefaultMute;
              else
                  return (bool)ViewState["Mute"];
          }
          set
          {
              if (value != DefaultMute)
                  ViewState["Mute"] = value;
              else
                  ViewState["Mute"] = null;
          }
      }
      [Bindable(true), Category("Settings"), Description("How much times will video play.")]
      int PlayCount
      {
          get
          {
              if (ViewState["PlayCount"] == null)
                  return DefaultPlayCount;
              else
                  return (int)ViewState["PlayCount"];
          }
          set
          {
              if (value < 1)
                  value = 1;
              if (value != DefaultPlayCount)
                  ViewState["PlayCount"] = value;
              else
                  ViewState["PlayCount"] = null;
          }
      }

      [Bindable(true), Category("Settings")]
      System.Single Rate
      {
          get
          {
              if (ViewState["Rate"] == null)
                  return DefaultRate;
              else
                  return (float)ViewState["Rate"];
          }
          set
          {
              if (value < 0.0)
                  value = (float)1.0;
              if (value != DefaultRate)
                  ViewState["Rate"] = value;
              else
                  ViewState["Rate"] = null;
          }
      }
      [Bindable(true), Category("Settings")]
      bool StretchToFit
      {
          get
          {
              if (ViewState["StretchToFit"] == null)
                  return DefaultStretchToFit;
              else
                  return (bool)ViewState["StretchToFit"];
          }
          set
          {
              if (value != DefaultStretchToFit)
                  ViewState["StretchToFit"] = value;
              else
                  ViewState["StretchToFit"] = null;
          }
      }
      [Bindable(true), Category("Settings"), Description("Set how player will look like.")]
      Enumerations.PlayerMode uiMode
      {
          get
          {
              if (ViewState["uiMode"] == null)
                  return DefaultUIMode;
              else
                  return (Enumerations.PlayerMode)ViewState["uiMode"];
          }
          set
          {
              if (value != DefaultUIMode)
                  ViewState["uiMode"] = value;
              else
                  ViewState["uiMode"] = null;
          }
      }
      [Bindable(true), Category("Settings"), Description("Set sound volume")]
      int Volume
      {
          get
          {
              if (ViewState["Volume"] == null)
                  return DefaultVolume;
              else
                  return (int)ViewState["Volume"];
          }
          set
          {
              if (value != DefaultVolume)
                  ViewState["Volume"] = value;
              else
                  ViewState["Volume"] = null;
          }
      }
        #endregion
      #region Private functions
      private string getPlayerMode()
      {
          switch (uiMode)
          {
              case Enumerations.PlayerMode.Invisible:
                  return "invisible";
              case Enumerations.PlayerMode.Mini:
                  return "mini";
              case Enumerations.PlayerMode.None:
                  return "none";
              default:
                  return "full";
          }
      }
      #endregion
 
      #region Render
      [Description("Render control, depending of property values")]
      protected override void RenderContents(HtmlTextWriter output)
      {
            StringBuilder content = new StringBuilder();
            content.Append("<object width="\" height="\" mode="hold" />                  "\" CLASSID=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" VIEWASTEXT>\n");
            content.Append("<param name="\" value="\" autostart="">\n");
            content.Append("<param name="\" value="\" movieurl="">\n");
            content.Append("<param name="\" value="\" enabled="">\n");
            content.Append("<param name="\" value="\" balance="">\n");
            content.Append("<param name="\" value="\" currentposition="">\n");
            content.Append("<param name="\" value="\" enablecontextmenu="">\n");
            content.Append("<param name="\" value="\" fullscreen="">\n");
            content.Append("<param name="\" value="\" mute="">\n");
            content.Append("<param name="\" value="\" playcount="">");
            content.Append("<param name="\" value="\" rate="">");
            content.Append("<param name="\" value="\" stretchtofit="">");
            content.Append("<param name="\" value="\">");
            if(Volume >= 0)
                  content.Append("<param name="\" value="\" volume="">");
            content.Append("");
            output.Write(content.ToString());
      }
}
#endregion
#region Enumerations
namespace Enumerations
{
      [Description("Player mode can be Invisible, None, Mini and Full")]
      public enum PlayerMode
      {
            Invisible = 0,
            None = 1,
            Mini = 2,
            Full = 3
      }
}
#endregion 
//        protected void Page_Load(object sender, EventArgs e)
//        {
            
           
//        }
       
//}

</param></param></param></param></param></param></param></param></param></param></param></param></param>

推荐答案

看看这些文章:
ASP.NET Media Player控件 [ ^ ]
ASP.NET MediaPlayer控件介绍 [ ^ ]
Have a look at these articles:
ASP.NET Media Player Control[^]
Introduction to the ASP.NET MediaPlayer Control[^]


这篇关于如何使用媒体播放器控件在asp.net 3.5中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆