Using Media Player in the web page

xiaoxiao2021-03-06  41

The method of embedding Media Player in the web page is relatively simple, as long as it is in HTML, as shown below.

where ID is the name of the object, when the user When JavaScript is controlled to control Media Player, you can use the name of the object to access. CodeBase indicates that you can get from the URL specified when you have no Player controls in the user's browser.

Of course, you can use to specify parameters for when establishing a Player object. As follows:

The "FileName" parameter represents the logistics or stream of MEDIA Player to play. "ShowControls" indicates whether a control bar is displayed during playback. Madia Player has a lot of parameters, and we will not be detailed here. Readers If you need to know more detailed content, you can refer to the relevant part of the Media Player SDK.

If the user needs to control the Media Player to be controlled with JavaScript.

In this example, Media Player is embedded in the web page, with some buttons on the right side of Media Player, using these buttons users to control the MEDIA Player's playback activity.

The HTML code of these buttons is as follows:

if (g_Browser == "Netscape") document.WMPlay.SetCurrentPosition (0); elsedocument.WMPlay.CurrentPosition = 0;} function PauseClick () {document.WMPlay.Pause ();} function PlayPauseClick () {var state; if (g_browser == "netscape") state = document.wmplay.getplayState (); elsestate = document.wmplay.PlayState; if (state == 0) Document.wmplay.Play (); else if (state == 1) Document .Wmplay.Play (); else if (state == 2) Document.wmplay.pause ();} // -> From this example, you can see that when the user is single, Its corresponding onclick function will be called. In the JavaScript function, you can directly control the activity of the player directly, such as start playing, stop playing or occupying the playback, and zooming in zooming. In addition to the action such as a mouse, an embedded Media Player can be controlled by an event. Microsoft? Windows Media? Player supports a lot of events, with ordinary mouse events, such as the mouse click, double-click, mouse movement, mouse keys and release, etc., there are also some events for Media Player. Events with direct relationships with streams include: OpenStateChange, PlayStateChange, Buffering, Markerhit, ScriptCommand, etc. Below we will briefly introduce these important events.

1 OpenStateChange Event OpenStateChange event indicates that the status of Player has changed. The open state of Media Player is: 0 indicates that the stream has been closed (NSCLOSED) 1 indicating that the ASX file (NSLoadingAsx) 2 indicates that the NSC file (NSLoadingNSC) 3 indicates that the Media Server (NSLocating) 4 indicates that is being with Media Server Establishing a connection (nsconnecting) 5 indicates that the flow information is being opened or listened to the flow information. The format of the OpenStateChange event is processed by the stream information has been opened (NSOpen). ) "Language =" jscript "> // INSERT Script commands // where MediaPlayer is the name when the Media Player object defined in .

2 PlayStateChange event PlayStateChange event indicates that the playback status of Media Player has changed, and Media Player may be: 0 Play has stopped (MPSTOPPED) 1 Playing pause (MPPASED) 2 is playing (MPPLAYING) 3 is waiting to start (MPWAITING) 4 Front Search (MPScanForward) 6 Backward Search (MPSkipForward) 7 Backward Jumping (MPSkipReverse) 8 stream Has been closed (MPCLOSED) The method of processing the event with JavaScript: