Click to See Complete Forum and Search --> : Volume...


dmason165
03-15-2003, 09:09 PM
Hello to all...

Wondering if anyone out there could give me some info. on using JavaScript to control volume.

Thanks for your help.

~D

2 peachy
03-15-2003, 09:19 PM
for live audio

function volumeit()
{
curvol=document.volform.level.value
Icurvol=parseInt(curvol)
document.tester.setvol(Icurvol)
}


html to set up volume control button and indicator:
<INPUT NAME="volcontrol" TYPE=Button VALUE="Set volume" onClick="volumeit()">
<INPUT NAME="level" TYPE=Text VALUE="100" SIZE="3" MAXLENGTH="3">

dmason165
03-15-2003, 10:33 PM
Thank you for replying.

What does live audio mean exactly? I have a video clip embedded in a web page, but would like for the user to control the volume with onMouseOver.

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 downvol()
{
nowvol=document.tester.GetVolume()
nowvol=nowvol-10
if(nowvol<0)
{
nowvol=0
}
document.tester.setvol(nowvol)
document.imagemapform.levelindicator.value=nowvol
}

function upvol()
{
nowvol=document.tester.GetVolume()
nowvol=nowvol+10
if(nowvol>100)
{
nowvol=100
}
document.tester.setvol(nowvol)
document.imagemapform.levelindicator.value=nowvol
}
</script>

<body>
<img src="/VolDown.GIF" width="116" height="58" style="cursor:hand" alt="Volume Down" border="0" onMouseOver="downvol()">

<img src="/VolUp.gif" width="114" height="59" style="cursor:hand" alt="Volume Up" border="0" onMouseOver="upvol()">
</body>

I keep getting errors though. What do you suggest?

Thanks again.

~Darron

2 peachy
03-16-2003, 01:31 AM
What type of video clip do you have embedded into your web page ?

2 peachy
03-16-2003, 01:47 AM
<!-- two steps to install -->
<!-- 1. Add this javascript to the head of your document -->

<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>

<!-- 2. Add these html codes in the body section of your page and add your audio file url -->
<center><embed src="http://URL of song" hidden="true" autostart="false" loop="1" name="firstsound" mastersound>
<table width="50%" border="0" bgcolor="242424" cellspacing="1">
<tr bgcolor="white"><td align="center">
<a href="javascript:document.firstsound.play()">Play</a>
</td><td align="center">
<a href="javascript:document.firstsound.pause()">Pause</a>
</td><td align="center">
<a href="javascript:document.firstsound.stop()">Stop</a>
</td><td align="center">Vol<a href="javascript:changeVolume(-10)"><b> -</b></a> <a href="javascript:changeVolume(10)"><b>+</b></a>
</td></tr></table><center>

dmason165
03-16-2003, 08:12 AM
2 Peachy,

Thank you for the posts last night and this morning. I apologize for not answering your question more promptly.

The type of video I have embedded into my webpage is .avi file. It's a news broadcast.

First I tried your code into a blank .html page to see if it would return any errors. None. I was gettin' very excited! Then, I tried implementing your code into my page with the video clip. My webpage's code looked like this:

<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:confused: 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"

Did I do something wrong? Now what do I do?

Thanks again for your help. I know this must get frustrating for you JS gurus out there. But don't give-up on us:) One day, maybe I'll be able to do what you do and help people in the same position I'm in now. You guys have been more help for me than you'll ever know and I'm sure it's like that for most others seeking your wisdom in this forum.

Hope to hear from someone soon.

~D