Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted
Updated 25-Jul-10 20:10pm
v5

1 solution

 
Share this answer
 
Comments
fwr 26-Jul-10 2:03am    
thanks sandeep,but ihave problem.i have downloaded the dll of media player and it runs when i simply drag and drop the media player control and specify the path of my vedio file.but the code for how to build media player that i have written in .cs file,i am not understanding.how can i call these methods and where so that i can handle multiple vedio files.plz help.
fwr 26-Jul-10 2:12am    
Reason for my vote of 4
for quick response and providing good reference.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900