View Full Version : Javascript Volume Controll

01-07-2007, 05:43 PM
Hi all, i am trying to controll the volume of an embeded windows media player VIA javascript, and found this code

function VolumeUp() {
if (document.MediaPlayer.Volume+1000<0) {
function VolumeDown() {
Now this works for incrementing and decreasing the volume, but i dont get where 1000 comes from or why "if volume is less than 0" for incrementing...
It makes no real sence.
I thought volume was on a scale of 1 to 100....
Can anyone please explain to me?
Oe provide a code that lets me set volume from 1 to 100?
Eather would be wery appriciated.
Thanks for your time

Philip M
01-07-2007, 06:52 PM
Volume is on a scale from -10000 to +10000. So 1000 is a 5% increase or decrease. 0 is the default or mid position.

In practice anything under -4000 is likely to be inaudible, and over +4000 will shatter your eardrums!

01-07-2007, 08:34 PM
Thank you so much, that really helps, but i am nowa bit confused, i've never had to figure out precentages for
a number ranging from negative to positive.
So if i wanted to find the volume on a scale of 1 to 100 (or in precent)
with the volume being 20

precent = 20
precentValue = (10000*precent)/100
calculatedVolume = (precentValue*2)-10000
document.MediaPlayer.Volume = calculatedVolume

Would that work?
Also, i dont want to bust anyone's eardrums, or go way too under with the volume.
4000 would be unpleasent, so what would be a pleasant range?

Philip M
01-08-2007, 08:51 AM
What is a precent?

Why do you not simply set the volume as an absolute value? Especially as you say that percentages are a bit advanced for you. ;)

As I said,
a value for volume of 0 is the default or mid position. Normal comfortable listening.Negative values reduce the sound. Positive values increase it. OK?