Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use Windows Media Player on my website?

Streaming Media

How do I use Windows Media Player on my website?

by  tanderso  Posted    (Edited  )
You need to embed your player into the page using the <object> tag for IE and the <embed> tag for NS. You can encapsulate the <embed> in the <object> so that IE only sees the <object> and NS only sees the <embed>.

eg:
[tt]
<OBJECT
ID="Video"
WIDTH="320"
HEIGHT="240"
CODEBASE="http:// activex.microsoft.com/ activex/ controls/ mplayer/ en/ nsmp2inf.cab#Version=5,1,52,0701"
CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Windows Media Player components..."
TYPE="application/x-oleobject">

<PARAM NAME="FileName" VALUE="">
<PARAM NAME="ShowControls" VALUE="0">
<PARAM NAME="ShowStatusBar" VALUE="0">
<PARAM NAME="ShowDisplay" VALUE="0">
<PARAM NAME="AnimationAtStart" VALUE="1">
<PARAM NAME="TransparentAtStart" VALUE="0">
<PARAM NAME="AutoStart" VALUE="1">
<PARAM NAME="AllowChangeDisplaySize" VALUE="1">

<EMBED
TYPE="application/x-mplayer2"
PLUGINSPAGE="http:// www.microsoft.com/ Windows/ Downloads/ Contents/ Products/ MediaPlayer/"
SRC=""
NAME="Video"
WIDTH="320"
HEIGHT="240"
ShowControls="0"
ShowStatusBar="0"
ShowDisplay="0"
AnimationAtStart="1"
TransparentAtStart="0"
AutoStart="1"
AllowChangeDisplaySize="1">
</EMBED>
</OBJECT>
[/tt]
[sub]Ignore the spaces after the slashes in the URLs... they are only there so it would line break and not scroll all the way across the page.
[/sub]
Now, in order to access the plugin from JavaScript, it can be referenced as document.Video or, what I like to do is to name a simple variable:
[tt]
var Player = document.Video;
[/tt]
To assign a file, you should do one of two things. One, you could set the FileName and SRC attributes in the tags. Two, you could set it via JavaScript:
[tt]
if (IE) {Player.FileName = your_file;}
else {Player.SetFileName(your_file);}
[/tt]
This way you can set it dynamically by choosing amongst several files, for instance. your_file can be any media type that WMP can play (mp3, wav, asf, wmf, etc).

In order to play the file, you should use:
[tt]
Player.Play();
[/tt]
There are many other functions you can use, such as stop, fast forward, pause, rewind, etc. There are also other attributes you can access such as the position, packets received, reception quality, etc. Download the WMP SDK from http://www.microsoft.com for more info on that.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top