Forum Moderators: open

Message Too Old, No Replies

Starting and stopping wav files

Starting and stopping wav files

         

Circuits

9:22 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



I need to be able to programmatically start and stop a wav file so that I can synchronize the music with some movement.

I can do it with a midi files but not the wav file.

This works:

<HTML><HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
sstatus=0;

function togglemusic()
{
if (sstatus==1)
{
sstatus=0;
document.music.play();
}
else
{
sstatus=1;
document.music.stop();
}
}

setInterval("togglemusic()", 10000);

</SCRIPT>

<embed name="music" SRC="pinball.mid"
loop=true autostart=false hidden=true mastersound volume="50">

</BODY>
</HTML>

but this doesn't:

<HTML><HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
sstatus=0;

function togglemusic()
{
if (sstatus==1)
{
sstatus=0;
document.music.play();
}
else
{
sstatus=1;
document.music.stop();
}
}

setInterval("togglemusic()", 10000);

</SCRIPT>

<embed name="music" SRC="guadalajara.wav"
loop=true autostart=false hidden=true mastersound volume="50">

</BODY>
</HTML>

Does anybody know why? This should have been a 10 minute task and I've been on it for 4 days.

hakre

5:44 pm on Jul 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



maybe the plugin for the wave file does not support the .play() function?

or does the plugin works at all. have you tested with autoplay on?

Circuits

5:53 pm on Jul 24, 2003 (gmt 0)

10+ Year Member



Hi,

Thanks for replying.

The plugin does work because I can play it with autostart=true. The problem is with the play() and stop() functions which work for the midi file but not for the wave.

I'm a bit of a novice regarding plugins. I don't really understand which plugin the browser is trying to use, I don't know to check if it supports play() and stop() and I don't know how to change the plugin to another.

Can you help?

hakre

1:50 am on Jul 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't really understand which plugin the browser is trying to use

it's long ago since i used plugins. i think it was netscape 2.01 or so ;).

nevertheless, if a file type is well known (like wav), there might be lot's of different plugins and that's bad news for you, because you don't know which one the user of your site installed. and this answers your second question: you just can not now.

one solution with the wav playing might be a flash movie with enabled fs_commands. you can 'remote control' the movie via javascript (java has to be enabled, too) and then you can start and stop the sound. you now a bit about flash?

SethCall

4:22 am on Jul 25, 2003 (gmt 0)

10+ Year Member



ah! Hakre! Dont confuse javascript and java! ;)

Don't you mean, "Javascript" has to be enabled too?

Circuits

9:34 am on Jul 25, 2003 (gmt 0)

10+ Year Member



I've never used Flash, although there's nothing to stop me learning.

However, won't the same problem arise? Isn't Flash just another plugin? How do I check that all my users have the correct version installed?

Circuits

8:55 pm on Jul 25, 2003 (gmt 0)

10+ Year Member



I've made some progress. The following seems to work reasonably consistently:

<object id="music" width="1" height="1"
classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"
standby="Loading Windows Media Player components..."
type="application/x-wav">
<param name="FileName" value="guadalajara.wav"></param>
<param name="AutoStart" value="False"></param>
<param name="Hidden" value="True"></param>
</object>

It responds to both the play() and stop() commands.

Is this a good way to do it? Presumably this will only work on Windows. Are there any other time-bombs here?

tedster

9:11 pm on Jul 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Isn't Flash just another plugin? How do I check that all my users have the correct version installed?

There's an attribute called "codebase" you can use in the Flash object tag that dictates the version of Flash required. If someone doesn't have a recent enough version they automatically get a notice to upgrade.

But you wouldn't even have to worry about using that attribute - you're using basic functions and any version of Flash should work - 97% penetration I'd say, and it will work on Macintosh.