Forum Moderators: open

Message Too Old, No Replies

Javascript wait and change volume.

Javascript, Audio, Fade-In, Volume

         

stu_u2k

3:03 pm on Sep 14, 2007 (gmt 0)

10+ Year Member


Hello there people, this has been doing my head in for ages now & a frineds to, basically i have a Vista Sidebar Gadget in the form of a Alarm Clock, it all works well but i really want to add the funcion of Audio Fade-In...

Now as far as i am aware the code for this directly does not exist so i think it will have to be Play Sound, Wait, Increase Sound, Wait Increase Sound etc until complete, now this does not have to be an adjustable but a set Fade-In duration would be fine, any help would be appriciated.

function chooseSound()

{

var shellitem = System.Shell.chooseFile(true, "Music files:*.mp3;*.wav;*.m3u;*.wpl;*.asx;*.wma::", "", ""[smilestopper]);

if(shellitem!=null)

{

soundpath.innerText = shellitem.path;

Player.settings.volume = 10;

Player.URL = soundpath.innerText;

Player.Controls.play();
}
}

}

That is the working code above, i have tried adding the following but cant get it to work what ever i do...

for(i = 0; i < 100; i++){
Player.settings.volume = $i;
<setTimeout($i, 1000)>

Thanks in advanced.

cmarshall

3:26 pm on Sep 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Stu, welcome to WebmasterWorld!

I'm not exactly sure of what it is you are doing. The code you are showing is not syntactically correct.

It also looks like you are trying to execute asynchronous code synchronously.

You can't do that.

I recommend that you give the little treatise I wrote on JavaScript scope [webmasterworld.com] a browse. You can skip right to the finished example [webmasterworld.com] if you don't want to read about how you get there. It may give you a good idea on how to handle it.

stu_u2k

12:02 am on Sep 15, 2007 (gmt 0)

10+ Year Member


Thanks i read throught that but im still lost, i should prob mention i am a n00b in the coding world.

Let me just layout what i am trying to achive & how i tried it using your advise, all i want this function to do it to wait a predetermind amount of time & then change the volume of the sound its playing, i have pasted below an what i have tried after reading your article (thanks again) but the code just gets ignored like its not there at all.

So in theory, or at least my theory (which counts for little) the code below should Start the music off with the volume at 10% & then after 5 seconds change the volume to 100%.

//-----------------Start--

function chooseSound()
{
var shellitem = System.Shell.chooseFile(true, "Music files:*.mp3;*.wav;*.m3u;*.asx;*.wpl;*.wma::", "", ""[smilestopper]);
if(shellitem!=null)
{
soundpath.innerText = shellitem.path;
Player.settings.volume = 10;
Player.URL = soundpath.innerText;
Player.Controls.play();
}
}

//-----------------

function StartProcess() {
setTimeout ( Callback, 5000 );
}
function Callback() {
Player.settings.volume = 100;
}
StartProcess();

//------------------END--

Maybe its my misunderstanding at that you can only set volume when you are starting the action, maybe you know? I certainly dont. LOL

Hope this clears things up alittle.

stu_u2k

12:12 am on Sep 15, 2007 (gmt 0)

10+ Year Member


Ok a short while after that reply i left i realised something else...

Player.settings.volume = 10;

Just doesnt work what so ever in my code, if i set the start value to 10 or 100 i get the same volume of sound to start with, meaning as far as i know the timeout function is working correctly, but the sound it not being handled correctly!

cmarshall

2:08 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not familiar with the Player class.

Is this a class provided by a 3rd party?

stu_u2k

3:33 am on Sep 15, 2007 (gmt 0)

10+ Year Member


Kind of, its a desktop widget for Vista, i downloaded it from an official site but unfortunatley there is no way for me to contact the Author, shame because loads of people on there want the playlist function i have added already but i wont release it without consent, its not copyrighted or anything but just curtosey.