Click to See Complete Forum and Search --> : Can't figure out this volume thing...someone PLEASE help!
dmason165
03-18-2003, 09:22 AM
Hello to all,
Wondering if anyone out there could give me some info. on using JavaScript to control volume. I can't get an answer anywhere.
I have already set the volume icons in place, however, I continue to get an error when using the following code:
<script language="JavaScript">
function changeVolume(step) {
var vol = document.firstsound.GetVolume();
vol += step;
if (vol > 100) vol = 100;
if (vol < 0) vol = 0;
setVolume(vol);
}
function setVolume(vol) {
document.firstsound.setvol(vol);
}
.
.
.
</script>
<body>
.
.
.
<img src="/VolDown.GIF" width="116" height="58" style="cursor:hand" alt="Volume Down" border="0" onMouseOver="changeVolume(-10)">
.
.
.
<img src="/VolUp.gif" width="114" height="59" style="cursor:hand" alt="Volume Up" border="0" onMouseOver="changeVolume(10)">
.
.
.
</body>
When I went to test this, I got an error. It was a no go. The error was from this line:
var vol = document.firstsound.GetVolume();
and it said:
"'document.firstsound' is null or not an object"
Anyone have any ideas?
Thank you very much for your time and your help.
~dmason165
gil davis
03-18-2003, 09:29 AM
You have neglected to post the code that you think creates the objectdocument.firstsound
dmason165
03-18-2003, 09:37 AM
What would be an example of what would create the object?
gil davis
03-18-2003, 09:46 AM
I have no idea. Is it your code, or did you "borrow" it from someone?
Posting a link or attaching your entire page would probably be a good idea. It would save us all a lot of fishing.
dmason165
03-18-2003, 10:05 AM
I did "borrow" this code. My page is not on the Net yet. But, here is an attachment of the code.
Sorry about that. Still learning.
~dmason165
gil davis
03-18-2003, 12:08 PM
The name of the object is "MediaPlayer1". You can access it using eitherdocument.MediaPlayer1.Volumeordocument.getElementById("MediaPlayer1").VolumeA 0 value sets maximum volume. Lowest volume is -10000. The number of actual volume steps is dependent on the hardware that is running the player.
dmason165
03-19-2003, 03:42 PM
Gil Davis,
Thank you for the reply.
To ALL who can help:
I have this now for my code:
<script language= "JavaScript">
<!-- Begin
function setVolume(vol) {
document.MediaPlayer1.setvol(-5000);
}
function changeVolume(step) {
var vol = document.MediaPlayer1.Volume;
vol += step;
if (vol > 0) vol = 0;
if (vol < -10000) vol = -10000;
setVolume(vol);
}
function AreYouSure() {
var agree=confirm("Are you sure you want to exit?\nClick OK to exit.\nClick CANCEL to remain on this page.");
if (agree)
window.location="Home3.htm";
}
// End -->
</script>
</head>
<body lang=EN-US style='tab-interval:.5in'
oncontextmenu="return false";>
<p align="center"><strong><font color="#0000A0"><big><big><big><font face="Times New Roman, Times, serif"><em><font size="5">Baltimore's
WBAL-TV 11 News - Steel Plate Investigation<br>
"Steel Plates Are Creating Damage"<br>
Broadcasted Thursday, February 13, 2003</font></em></font></big></big></big><font face="Times New Roman, Times, serif"><br>
</font></font><font color="#FF0000" size="2" face="Times New Roman, Times, serif"><em>This
video requires MS Media Player version 6.4 (or higher).<br>
<br>
</em></font></strong></p>
<table border="0" width="100%">
<tr>
<td width="33%"><font face="Times New Roman, Times, serif">
<p align="center">
<object id="MediaPlayer1" width="680" height="525" 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="TheWBALChannel.com-11Investigates-SteelPlatesAreCreatingDamage.avi">
<param name="showcontrols" value="0">
<param name="enablecontextmenu" value="0">
<param name="autorewind" value="1">
<embed width="680" height="525" src="TheWBALChannel.com-11Investigates-SteelPlatesAreCreatingDamage.avi" showcontrols="0" enablecontextmenu="0" autorewind="1" ></embed></object>
</font> </tr>
</table>
<table border="0" width="100%">
<tr>
<td width="44%" align="right"><img src="/VolDown.GIF" width="116" height="58" style="cursor:hand" alt="Volume Down" border="0" onMouseOver="changeVolume(-500)"></td>
<td width="12%"><p align="center"><font face="Times New Roman, Times, serif"><strong><font color="#000000"><small><em><small>Run
time 3:49<br>
<br>
<a href="javascript:void AreYouSure()" Title="Click here to return Home.">Return
Home</a></small></em></small></font></strong></font></td>
<td width="44%"><img src="/VolUp.gif" width="114" height="59" style="cursor:hand" alt="Volume Up" border="0" onMouseOver="changeVolume(500)"></td>
</tr>
</table>
</body>
</html>
However, I am now getting an error report for the following line of code:
document.MediaPlayer1.setvol(-5000);
that states:
"Object doesn't support this property or method"
Does this mean that WMP doesn't support setvol() or what?
What I would like to do doesn't really seem to be all THAT impossible. I want to make it so onMouseover, a user can increase or decrease the video's volume.
I was actually reading some material online, and I actually want to FADE volume up or down (i.e. user holds cursor over "Volume Up" icon, and volume increases until the user removes the cursor or maximum volume has been achieved.)
Please help.
Thank you.
~dmason165
gil davis
03-19-2003, 04:17 PM
Originally posted by dmason165
"Object doesn't support this property or method"
Does this mean that WMP doesn't support setvol() or what?Yes, that is what it means. If you read the Microsoft SDK for MediaPlayer, you will find that the property for controlling volume is (oddly enough) called Volume. There is no method called setvol().
What, you didn't believe my last post?I was actually reading some material onlineWhat were you reading? Post a link.
You'll find something useful at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmp6sdk/htm/windowsmediaplayercontrolversion64scriptingreference.asp - that's where I started out. Version 9 supports the same set, but the info on V9 seems more geared towards C++ and VB rather than JS support. It seems that Volume is deprecated, and I couldn't find any equivalent method.
dmason165
03-19-2003, 11:44 PM
Gil Davis,
I followed the link you provided, and did a search for "volume". I came up with this:
function changeVolume(step) {
var vol = document.MediaPlayer1.Volume [ = -5000 ];
vol += step;
if (vol > -10000) vol = -10000;
if (vol < 0) vol = 0;
}
from MS's site which stated this:
Syntax:
HTML <BGSOUND VOLUME = iVolume... >
Scripting BGSOUND.volume [ = iVolume ]
Possible Values:
iVolume = Variant that specifies or receives the volume setting. Valid values range from -10,000 to 0, with 0 being full Wave Output volume.
The property is read/write. The property has no default value.
However, this is still returning an error. Have you been able to get this to work on your CPU? If you have, what is the exact code you are using? I have tried a lot of different codings but still get an error.
What, you didn't believe my last post?
This information I'm speaking of I found while I was trying to find a solution on my own. It was at the following site:
http://www.go2share.net/jsguide/liveaud.htm
However, I don't quite understand the objects and methods that this site provides. But it's definitely not that I didn't believe you ('cause I hadn't even gotten your response at this point). What I was referring to when I stated that, is that I saw on this page two methods which sound more like the effect I'm looking for as opposed to 1 step per onMouseover; didn't actually get a solution though.
The methods were:
fade_to({volume percent to fade to, without the "%"})
fade_from_to({volume % start fade}, {volume % end fade})
Check it out. There has to be a way to do this.
Thanks for your time and your help.
~dmason165
gil davis
03-20-2003, 06:10 AM
I couldn't get your example to work. It couldn't find the video file.
I've attached an example that works with music files. I've never tried to use a video. Just change the name of the wav file to something you have on your drive. You can also browse for a wav file. I believe the player must have a file loaded successfully before you can access any of the scripting commands.
The VOL+/VOL- buttons have to be clicked. The VOL+/VOL- links are for mouseover. The volume will change as long as the mouse is over the link, and stops changing when you mouseout.
dmason165
03-20-2003, 10:40 AM
Your code was right on the money!
I extracted what I needed and inserted it into my page (see my attachment). Works great!!! Thank you so very much!
To all,
Note: The volume controls given in the attachment below and the attachment provided by Gil Davis control WMP's volume, not your system volume. It acts similar to you sliding the volume bar up and down when using WMP. If you have any questions about any of the code in my attachment, don't hesitate to shoot me an e-mail or PM me.
Gil Davis, thanks again!
~dmason165
Note: My site is a local one, so if you want to use the coding from this attachment, you'll have to substitute my file sources for yours (i.e. media files and Volume Up & Volume Down icons/.gifs).