The VideoPresentations ClassThe VideoPresentations class is in the VideoPresentations.cs source code module (or the VideoPresentations.vb module for the VB.NET version). The properties and their description are contained in Table 20.1. There are a few public methods for the VideoPresentations class. They can be seen in Table 20.2. Two things must be done to use the VideoPresentations class. The first is to instantiate the class and set its properties so that the desired behavior will result. I suggest doing this in the code behind the module, but it can be done in the ASPX code if you prefer. The second thing that must be done is to output the JavaScript and HTML code into the ASPX code.
I'll talk about these steps in more detail in the section entitled "The Demonstration Application." Here, we'll take a look at how the VideoPresentations class works.
The VideoPresentations class has several private data members in which the JavaScript text is stored. The following is the string variable that contains the JavaScript startup code: private string m_strLoadCode = "<script language='JavaScript'>\r\n" + " function loadIt()\r\n" + " {{\r\n" + " var pluginJavaPeerRef = document.myform.VideoPlay;\r\n" + " if( NS4 )\r\n" + " {{\r\n" + " if (document.myform.VideoPlay != null)\r\n" + " {{\r\n" + " objPlayer = document.myform.VideoPlay;\r\n" + " sBrowser = \"notIE\";\r\n" + " document.appObs.setByProxyDSScriptCommandObserver(" + "pluginJavaPeerRef, true);\r\n" + " document.myform.VideoPlay.SetFileName ( \"{0}\" );\r\n" + " document.myform.VideoPlay.Play();\r\n" + " }}\r\n" + " }}\r\n" + " }}\r\n" + "</script>\r\n" + "\r\n"; The m_strLoadCode code string variable is private, but the data can be retrieved using the VideoPresentations.LoadCode property. Notice that the string expects a single argument, identified by the {0} that can be seen within the string. This string must be formatted in the LoadCode property's accessor, as follows: public string LoadCode { get { return( string.Format( m_strLoadCode, Filename ) ); } } Other private data members include m_strStyleData (accessed by the StyleData property), m_strStartupAndVars (accessed by the StartupCode property), m_strMarkerCode (accessed by the MarkerCode property), m_strScriptCommandCode (accessed by the ScriptCommandCode property), m_strMouseControlCode (accessed by the MouseControlCode property), m_strMarkerHitCode (accessed by the MarkerHitCode property), m_strStatusCode (accessed by the StatusCode property), and m_strPlayerObject (accessed by the PlayerObject property). Listing 20.5 shows all of the code for the VideoPresentations class except for the private data members. Listing 20.5 The VideoPresentations.cs Source Codepublic string StyleData { get { return( m_strStyleData ); } } public string StartupCode { get { return( m_strStartupAndVars ); } } public string LoadCode { get { return( string.Format( m_strLoadCode, Filename ) ); } } public bool UseMarkerCode { get { return( m_bUseMarkerCode ); } set { m_bUseMarkerCode = value; } } public string MarkerCode { get { return( string.Format( m_strMarkerCode, Directory ) ); } } public string ScriptCommandCode { get { return( string.Format( m_strScriptCommandCode, Directory ) ); } } public bool UseTOC { get { return( m_bUseTOC ); } set { m_bUseTOC = value; } } public string MouseControlCode { get { return( m_strMouseControlCode ); } } public string MarkerHitCode { get { return( m_strMarkerHitCode ); } } public string StatusCode { get { return( m_strStatusCode ); } } public string PlayerObject { get { return( string.Format( m_strPlayerObject, Directory, Filename, AnimationStart, TransparentStart, AutoStart, Volume, ShowControls ) ); } } public string VCRControl { get { return( m_strVCRControl ); } } public string Filename { get { return( m_strFilename ); } set { m_strFilename = value; } } public string Directory { get { return( m_strDirectory ); } set { m_strDirectory = value; } } public void AddTOCEntry( string strEntry ) { m_TOCEntries.Add( strEntry ); } public DataSet TOCList { get { // Create a new DataSet object. DataSet ds = new DataSet(); // Add a table named TOCEntry. ds.Tables.Add( "TOCEntry" ); // Add two columns, title and number. ds.Tables[0].Columns.Add( "Title" ); ds.Tables[0].Columns.Add( "Number" ); // Loop through each TOC entry. for( int i=0; i<m_TOCEntries.Count; i++ ) { // Create a string array that'll be // used to add the wor. string[] ThisRow = { m_TOCEntries[i], Convert.ToString( i + 1 ) }; // Add the row. ds.Tables[0].Rows.Add( ThisRow ); } // Return the DataSet object to caller. return( ds ); } } public string GetStyleCode() { return( StyleData ); } public string GetJavascriptCode() { string strScriptCode = StartupCode + LoadCode; if( UseMarkerCode ) { strScriptCode += MarkerCode; } strScriptCode += ScriptCommandCode; if( UseTOC ) { strScriptCode += ( MouseControlCode + MarkerHitCode ); } return( strScriptCode ); } public bool AnimationStart { get { return( m_bAnimationStart ); } set { m_bAnimationStart = value; } } public bool TransparentStart { get { return( m_bTransparentStart ); } set { m_bTransparentStart = value; } } public bool AutoStart { get { return( m_bAutoStart ); } set { m_bAutoStart = value; } } public int Volume { get { return( m_nVolume ); } set { m_nVolume = value; } } public bool ShowControls { get { return( m_bShowControls ); } set { m_bShowControls = value; } } public int SlideWidth { get { return( m_nSlideWidth ); } set { m_nSlideWidth = value; } } public int SlideHeight { get { return( m_nSlideHeight ); } set { m_nSlideHeight = value; } } public string SlideWindowCode { get { return( string.Format( m_strSlideWindowCode, Directory, SlideWidth, SlideHeight ) ); } } public string GetTOCCode() { // Start the string off with the <table> tag, // and <th></th> tags. string strRetCode = "<table border=0>\r\n <th>\r\n" + "Table of Contents\r\n </th>\r\n"; // Loop through each TOC entrie to create the HTML. for( int i=0; i<m_TOCEntries.Count; i++ ) { // Start the row. strRetCode += " <tr>\r\n"; // Start the column. strRetCode += " <td>\r\n"; // Create the link with all of the javascript // code. strRetCode += ( "<a href=\"#\" onclick=\"GoMarker(" + Convert.ToString( i + 1 ) + "); return false\"><div id=\"M" + Convert.ToString( i + 1 ) + "\" class=\"Marker\" onmousedown=\"TOCmouseDown();" + "\" onmouseout=\"TOCmouseOut();" + "\" onmouseover=\"TOCmouseOver();\">" + m_TOCEntries[i] + "</div></a>" ); // End the column. strRetCode += " </td>\r\n"; // End the row. strRetCode += " </tr>\r\n"; } // End the table. strRetCode += "</table>\r\n"; return( strRetCode ); } |