Simple Example of Scripting in a Web Page
You can easily embed the Windows Media Player control in an HTML file using any scripting language your browser recognizes. The following simple example uses Microsoft JScript to create a page that will play a file when you click on a button, and stop playing the file when you click on another button.
You can embed the Windows Media Player ActiveX control in a Web page using the following four steps:
- Create the Web page.
- Add the OBJECT tag.
- Add a user interface. In this case, two buttons.
- Add a few lines of code to respond when the user clicks on one of the buttons you have created.
Creating the Web Page
The first step is to create a valid HTML Web page. The following code is the minimum needed to create a blank but valid HTML page:
<HTML> <HEAD> </HEAD> <BODY> </BODY></HTML>
Adding the OBJECT Tag
Once you have created a Web page, you need to add an OBJECT tag. This identifies the ActiveX control to the browser and sets up any initial definitions. You must place the OBJECT tag in the BODY of the code. If you place it in the BODY, the default user interface of Windows Media Player will be visible. If you want to create your own user interface, set the height and width attributes to 0 (zero). You can also set the Player.uiMode property to "invisible" when you want to hide the control, but still reserve space for it on the page. The following code is recommended when you provide a custom user interface:
<OBJECT ID="Player" height="0" width="0" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"></OBJECT>
The following OBJECT tag attributes are required:
ID
The name that will be used by other parts of the code to identify and use the ActiveX control. You can choose any name you want, as long as it is a name that is not already used by HTML, HTML extensions, or the scripting language you are using. In this example, the name Player is used, but you could also call it MyPlayer or something else. Just pick a name that is unique to that Web page.
CLASSID
A very large hexadecimal number that is unique to the control. Only one control has this number and it is the Windows Media Player ActiveX control. To prevent typographical errors, you can copy and paste this number from the documentation. Versions of the Windows Media Player control prior to version 7.0 had a different CLASSID.
Adding a User Interface
HTML allows a vast wealth of user interface elements, allowing the user to interact with your Web page by clicking, pressing keys, and other user actions. Adding a few INPUT buttons is the easiest way to provide a quick user interface. The following code creates two buttons that can respond to the user. Clicking one button starts the media stream playing and the other button stops it:
<INPUT TYPE="BUTTON" NAME="BtnPlay" VALUE="Play" OnClick="StartMeUp()"><INPUT TYPE="BUTTON" NAME="BtnStop" VALUE="Stop" OnClick="ShutMeDown()">
The name of the button is used to identify the button to your code; the value is the label that will appear on the button, and the OnClick attribute identifies which part of your scripting code will be called when the button is clicked.
Adding Scripting Code
Scripting code adds interactivity to your page. Scripting code can respond to events, call methods, and change run-time properties. Extended scripts are enclosed in a SCRIPT tag set. The SCRIPT tag tells the browser where your scripting code is and identifies the scripting language. If you do not identify a language, the default language will be Microsoft JScript.
It is good authoring practice to enclose your script in HTML comment tags so browsers that do not support scripting do not render your code as text. Put the SCRIPT tag anywhere within the BODY of your HTML file and embed the comment-surrounded code within the opening and closing SCRIPT tags.
The following Microsoft JScript code example calls the Windows Media Player control and performs an appropriate action in response to the corresponding button click.
<SCRIPT><!--function StartMeUp (){ Player.URL = "laure.wma";}function ShutMeDown (){ Player.controls.stop();}--></SCRIPT>
The example function, StartMeUp, is called when the button marked Play is clicked, and the ShutMeDown function is called when the Stop button is clicked.
The code inside StartMeUp uses the URL property to define a path to the media. The media will start playing immediately.
The ShutMeDown code calls the stop method of the Controls object. Note that the Controls object is called through the controls property of the Player object, which has the ID value of "Player".
The following code shows a complete example.
<HTML><HEAD></HEAD><BODY><OBJECT ID="Player" height="0" width="0" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"></OBJECT><INPUT TYPE="BUTTON" NAME="BtnPlay" VALUE="Play" OnClick="StartMeUp()"><INPUT TYPE="BUTTON" NAME="BtnStop" VALUE="Stop" OnClick="ShutMeDown()"><SCRIPT><!--function StartMeUp (){ Player.URL = "laure.wma";}function ShutMeDown (){ Player.controls.stop();}--></SCRIPT></BODY></HTML>
Note that you must provide a valid URL to a valid file name in the URL property. In this case the assumption is that the file laure.wma is in the same directory as the HTML file.
這個是從MSDN的SDK中copy的一段,不過說明了一些問題,比如說play和stop的問題,這個在WEB的ASP版常常看到的MEDIA PLAYER 的問題,這個很容易說明的用mediaid.controls.play()和media.control.stop();加以控制
Controls.currentItem
The currentItem property specifies or retrieves the current media item.
Syntax
player.controls.currentItem
Possible Values
This property is a read/write Media object.
Remarks
This method works only with items in Player.currentPlaylist. Calling currentItem with a reference to a saved media item is not supported.
Example Code
The following JScript example uses currentItem to set the player control current media item to the selected value in an HTML SELECT element. The current playlist was first specified by using PlaylistCollection.getByName. The Player object was created with ID = "Player".
<SELECT ID = playItem NAME = "playItem" LANGUAGE = "JScript" /* Specify the current item when the selected list value changes. */ onChange = "Player.controls.currentItem = Player.currentPlaylist.item(playItem.value);"> /* Fill the SELECT element list with three items that match the songs in the playlist. */ <OPTION VALUE = 0 >Laure <OPTION VALUE = 1 >Jeanne <OPTION VALUE = 2 >House</SELECT>Controls.currentItemThe currentItem property specifies or retrieves the current media item.
Syntax
player.controls.currentItem
Possible Values
This property is a read/write Media object.
Remarks
This method works only with items in Player.currentPlaylist. Calling currentItem with a reference to a saved media item is not supported.
Example Code
The following JScript example uses currentItem to set the player control current media item to the selected value in an HTML SELECT element. The current playlist was first specified by using PlaylistCollection.getByName. The Player object was created with ID = "Player".
<SELECT ID = playItem NAME = "playItem" LANGUAGE = "JScript" /* Specify the current item when the selected list value changes. */ onChange = "Player.controls.currentItem = Player.currentPlaylist.item(playItem.value);"> /* Fill the SELECT element list with three items that match the songs in the playlist. */ <OPTION VALUE = 0 >Laure <OPTION VALUE = 1 >Jeanne <OPTION VALUE = 2 >House</SELECT>顯然controls有很多東西,我們可以控制的也很多
Controls.nextThe next method sets the current item to the next item in the playlist.
Syntax
player.controls.next()
Parameters
This method takes no parameters.
Return Values
This method does not return a value.
Remarks
If the playlist is on the last entry when next is invoked, the first entry in the playlist will become the current one.
For server-side playlists, this method skips to the next item in the server-side playlist, not the client playlist.
When playing a DVD, this method skips to the next logical chapter in the playback sequence, which may not be the next chapter in the playlist. When playing DVD stills, this method skips to the next still.
Example Code
The following example creates an HTML BUTTON element that uses next to move to the next item in the current playlist. The Player object was created with ID = "Player".
<INPUT TYPE = "BUTTON" ID = "NEXT" NAME = "NEXT" VALUE = ">>|" onClick = " /* Check first to be sure the operation is valid. */ if (Player.controls.isAvailable('Next')) /* Move to the next item in the playlist. */ Player.controls.next();">
所有這些在微軟的sdk中都有的,大小為10M,可以下載很方便的
這裡僅僅寫了WEB的script中的一些用法,用VB VC一樣可以控制的,controls顯然是很方便的