Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Volume Controll

    Hi all, i am trying to controll the volume of an embeded windows media player VIA javascript, and found this code
    Code:
    function VolumeUp() {
            if (document.MediaPlayer.Volume+1000<0) {
     document.MediaPlayer.Volume=document.MediaPlayer.Volume+1000;
            }
    }
    function VolumeDown() {
            document.MediaPlayer.Volume=document.MediaPlayer.Volume-1000;
    }
    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
    ~Gabor

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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!

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Code:
    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?
    Last edited by gszauer; 01-07-2007 at 07:39 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •