Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


The Basics - Page 2

June 11, 2001

With all the great interactivity available to Windows Media let's start with the basics. As I mentioned before, Web page developers don't always want to be stuck with Microsoft's choice of buttons. The first step is using JavaScript to control the embedded Windows Media player using form style buttons. These have the advantage of being placed anywhere on the page and controlling the video, while the Microsoft controls must be placed directly below the video.

This will work with Netscape 4+ and IE 4+. Document Object Model (DOM) is a fancy term used to describe how elements on a Web page are addressed. This code embeds the video in the Web page. You will need to substitute your own video for yourfile.asx that I have used as a placeholder. Notice that we have turned off the Windows Media Player controls by setting ShowControls equal to false. Place the following code in the <body> of the document.

<OBJECT ID="WinMedia" width=160 height=120
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/
mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby=
"Loading Microsoft® Windows® Media Player components..."
type="application/x-oleobject">
<PARAM NAME="FileName" VALUE="yourfile.asx">
<PARAM NAME="AutoStart" Value="True">
<PARAM NAME="ShowControls" VALUE="False">
<PARAM NAME="ShowStatusBar" VALUE="True">
<EMBED type="application/x-mplayer2"
pluginspage="http://www.microsoft.com/Windows/
MediaPlayer/" SRC="yourfile.asx" name="WinMedia"
autostart=1 width=160 height=120 ShowStatusBar=true
ShowControls=false>
</EMBED>
</OBJECT>

[Lines 1-6 above are one line as are lines 11-15. They have been split for formatting purposes.]

Once we have the video embedded in the Web page we are ready to use our form style buttons to control the video. The following code creates three buttons, Play, Pause and Stop. Place the following in the <body> of the document below the embedded video described above.

<FORM NAME="PlayerButtons">
<INPUT NAME="Playbtn" TYPE="Button" VALUE="Play"
onclick="document.WinMedia.Play();">
<INPUT NAME="Pausebtn" TYPE="Button" VALUE="Pause"
onclick="document.WinMedia.Pause();">
<INPUT NAME="Stopbtn" TYPE="Button" VALUE="Stop"
onclick="document.WinMedia.Stop();">
</FORM>

[Lines 2 and 3 above are one line as are lines 4 and 5 and 6 and 7. They have been split for formatting purposes.]

These bits of JavaScript code are being used to control the Windows Media Player through Methods that are built into the WMP. The main methods that are exposed are:

OperationMethod
PlayMediaPlayer.Play();
PauseMediaPlayer.Pause();
StopMediaPlayer.Stop();
Previous TrackMediaPlayer.Previous();
Fast ReverseMediaPlayer.FastReverse();
Fast ForwardMediaPlayer.FastForward();
Next TrackMediaPlayer.Next();

This code is great if you want to use the built-in form buttons, but what if you want to use your own custom graphical buttons that allow you to control the look and feel? Using your own graphics allow the developer to build the video into the Web page and create an integrated application. While Windows Media Skins give you control over the player when in standalone mode, these skins can't be used to modify an embedded video. Fortunately, the code isn't much harder to use your own graphics.

<A HREF="javascript:document.WinMedia.Play()">
<IMG SRC="play.gif" WIDTH="75" HEIGHT="75" BORDER="0"
ALT="PLAY BUTTON"></A>

<A HREF="javascript:document.WinMedia.Pause()">
<IMG SRC="pause.gif" WIDTH="75" HEIGHT="75" BORDER="0"
ALT="PAUSE BUTTON"> </A>

<A HREF="javascript:document.WindMedia.Stop()">
<IMG SRC="stop.gif" WIDTH="75" HEIGHT="75" BORDER="0"
ALT="STOP BUTTON"> </A>

[Lines 1-3 above are one line as are 5-7 and 9-11. They have been split for formatting purposes.]

Controlling the Windows Media Player with JavaScript is really very easy. Where it gets difficult is when you start synchronizing video with other elements on the page, such as turning graphics into slide shows.

Windows Media: JavaScript Buttons
Synchronized Content - Page 3


Up to => Home / Multimedia / Windows_Media




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers