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!

Using Windows Media Player with 1 control button to stop and play

Streaming Media

Using Windows Media Player with 1 control button to stop and play

by  soonkhoo  Posted    (Edited  )
This code was helped by a few people and special thanks to Ben a.k.a Bangers for creating image swapping code. This discussion could be found at thread215-43476.

Basically, you have the embeded WMP and is controlled with only 1 button. When click on the Stop button, the image will swap to a Play button and the Audio will stop. Vice versa.

If you use this code, do make sure you set the correct files for your audio. It supports all kinds. If you want to see the WMP default controls on your site. Go to the <object> tag and set showcontrols to true. And if you don't want to autostart when entering your site. Set to false at the param. Do what ever you want. It works.

I had hidden the WMP. So if you want to see it...change the width and height greater than zero at the object tag.


[color red]<HTML>
<HEAD><TITLE>Windows Media Player Test</TITLE>

<script language="JavaScript">
<!--

var myImageOn = new Image();
myImageOn.src = 'Images/play.gif';

function imageSwap(){
if(document.mybutton.isOff){
document.mybutton.isOff = false;
document.mybutton.src = myImageOn.src;
document.mybutton.name = "BtnStop";
MediaPlayer1.Stop();
MediaPlayer1.CurrentPosition = 0;
}
else if(!document.mybutton.isOff)
{
document.mybutton.isOff = true;
document.mybutton.src="Images/stop-up.gif";
document.mybutton.name = "BtnPlay";
MediaPlayer1.Play();
}
}

//-->
</script>
</HEAD>
<BODY bgcolor="#EEEEEE">
<BR>

<object id="MediaPlayer1" width=0 height=0
classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/
nsmp2inf.cab#Version=6,4,5,715"
standby="Loading Microsoft« Windows MediaÖ Player components..."
type="application/x-oleobject" align="middle">
<param name="FileName" value="C:\My Music\UB40 - Red Red Wine.mp3">
<param name="ShowControls" value="False">
<param name="AutoRewind" value="True">
<param name="AutoStart" value="True">
<embed name="MediaPlayer1" width="27" height="17" filename="C:\My Music\UB40 - Red Red Wine.mp3" showcontrols="False" autorewind="True" autostart="True" src="C:\My Music\UB40 - Red Red Wine.mp3" align="middle">
</embed>
</object> <a href="javascript:imageSwap()"><img border="0" name="BtnStop" id="mybutton" isOff=true src="Images/stop-up.gif" width="27" height="23"></a>
<br>
<br><br><br>

</BODY>
</HTML>[/color]
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