View Full Version : How do I string sounds together?
spamfritter
12-19-2002, 11:53 PM
Hi,
I've just been sent here from the HTML board cos I ask a question and someone said to come on here for the answer. So here I am.
Firstly though I must warn you, I know nothing (I mean nothing) about Java apart from it's one of those rare things where Microsoft messed up (yay!).
My original message was:
I want to play sounds one after another but I can only play them all together or only play one. I wrote
<EMBED src=http://www. hidden=true loop="false" autostart="true" width="1" height="1">
<EMBED src=http://www. hidden=true loop="false" autostart="false" width="1" height="1">
<EMBED src=http://www. hidden=true loop="false" autostart="false" width="1" height="1">
<EMBED src=http://www. hidden=true loop="false" autostart="false" width="1" height="1">
<EMBED src=http://www. hidden=true loop="false" autostart="false" width="1" height="1">
<EMBED src=http://www. hidden=true loop="false" autostart="false" width="1" height="1">
with the links in there but I have no way to get them to play one after the other. Worse still I really don't want to record the sounds together as their on friends websites (I'm using them with permission don't worry!). Any help would be great. (if anyone knows how to put in a 1 sec pause between them too that would be really great!)
Sweenster said to use a i-frame but I'm not great with HTML either so I still didn't know what to do and anyway I know enough to know that this is more than 1 page and I need to do it in one page.
Bassleader then suggested I try here and said about using only one embed tag and using javascript to manipulate it. I wouldn't know how to do it exactly, maybe calling a function via a timeout that sets the source attribute.
and said to do this I should try the Java board so here I am.
Any help would be much appreciated.
It's not homework or anything like that (I'm doing Chemistry, Physics and Maths (Pure/Applied) A-levels so it has no relevance to my curicullum).
Thanks and Merry Christmas
Spamfritter
krycek
12-20-2002, 12:09 AM
hmmm that's an interesting question.
I have never really used sounds in the webpages I have done, but off the top of my head, I would suggest something like this:
I know that you can tell the sounds to play using JavaScript, so I would set all of the sounds to autostart="false". Then I would call the function to start the sounds either when the current sound has finished (if that can be detected) or else after a set interval.
Try this:
In between head tags:
<SCRIPT LANGUAGE="JavaScript">
function play_sound(sound_name) {
eval('document.'+sound_name+'.FileName=document.'+sound_name+'.FileName');
}
</SCRIPT>
After body tag:
<EMBED SRC="buzz.wav" LOOP=false AUTOSTART=false MASTERSOUND name="buzz" HIDDEN=true VOLUME=70 WIDTH=0 HEIGHT=0 >
Wherever you want the sound to happen:
<a href="#" onMouseover="play_sound('buzz');">Play sound onMouseover</a>
by playing around with that you can get the sounds set up, then if you want them to play after each other, you will either have to call the next sound using a timeout, or else use an event that will fire when the sound finishes (I didn't have time to find one right now).
I have had no time to try that script, but it should work, I hope :) In any case in will probably help you with how to trigger the events.
::] krycek [::
PS - here is a script I found real quick, that I have simply copy & pasted (not been test but it looks like it may help):
<BGSOUND id="BGSOUND_ID" LOOP=1 SRC="jsilence.mid">
<EMBED NAME="Bach" SRC="Bach.mid"
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>
<script language="JavaScript">
<!--
ver=parseInt(navigator.appVersion)
ie4=(ver>3 && navigator.appName!="Netscape")?1:0
ns4=(ver>3 && navigator.appName=="Netscape")?1:0
ns3=(ver==3 && navigator.appName=="Netscape")?1:0
function playSound() {
if (ie4) document.all['BGSOUND_ID'].src='Bach.mid';
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes['audio/x-midi']
&& self.document.Bach.IsReady()
)
{
self.document.Bach.play()
}
}
function stopSound() {
if (ie4) document.all['BGSOUND_ID'].src='jsilence.mid';
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes['audio/x-midi']
)
{
self.document.Bach.stop()
}
}
//-->
</script>
<form name=myform>
<input type=button value="Play Sound" onClick="playSound()">
<input type=button value="Stop Sound" onClick="stopSound()">
</form>
spamfritter
12-20-2002, 02:16 PM
Thanks Krycek but after fiddling with this again and again I still couldn't get it to work.
I woke up last night (we're 8 hrs ahead of you here in England) and I thought I could just put in a pause before a sound then I can set a pause at the start of each sound and set autostart=true so that the effect is they appears to play one after another
for example:
if 1.wav = 5 secs
and 2.wav = 3 secs
and 3.wav = 7 secs
and i want a 1 sec pause between them
If i start all of them but put a pause of 6 (5+1) secs at the start of 2.wav and a pause of 10 (5+1+3+1) secs at the start of 3.wav they would appear to play one after another.
Also remember I know ABSOLUTELY nothing about java apart from the extremely basics (really extremely basics)
but a trigger sounds like a good idea too, If anyone has any ideas please put them forward
krycek
12-20-2002, 02:27 PM
heheh 8 hours ahead of who? :) I live in England :D And there are people on these forums from all over the world ;)
By the way, this is JavaScript, not Java, there is a difference but as you're new to it you wouldn't know that. :)
I will have a fiddle today if I get time, otherwise good luck :)
::] krycek [::
spamfritter
12-20-2002, 04:13 PM
not 8 hrs ahead of you.......
I also live in sunny (yeah right) England in the lovely county of suffolk. I meant 8hrs ahead of what I presumed was the majority of people as the clock on the forum is set to GMT-8 (which I believe is Pacific Time).
Sorry
Spamfritter
I have scripted playlist for my site that contains 85 music tracks.
The first track is selected at random then the tracks play in sequential order from that point.
When you enter my site there is a 15 second delay before the playlist starts this is to make sure my frameset has finished loading and the downloading of the first track.
Take a look here
www.huntingground.freeserve.co.uk/scripts/playlist.htm
spamfritter
12-20-2002, 11:19 PM
... and all this means it still doesn't work I've tried
<html>
<SCRIPT language=JavaScript>
<!-all times must be in millisecs>
timer=""
index = 0
loadtime = 2500 // time allowed for downloading
loadnum = 0
stopped = 1
song=new Array() // File name, Song Title, Playing Time
song[song.length]=new Array("http://www.necrosdomain.co.uk/downloads/tvthemes/gadget.wav","Inspector Gadget",73000)
song[song.length]=new Array("http://www.necrosdomain.co.uk/downloads/tvthemes/dangermo.wav","Dangermouse",33000)
song[song.length]=new Array("http://www.tvthemetunes.net/_tv/b/buttonm.wav","Button Moon",32000)
song[song.length]=new Array("http://www.tvthemetunes.net/_tv/b/bodgbadg.mp3","Bodger & Badger",17000)
song[song.length]=new Array("http://www.trenchman.com/sounds/hammer.wav","Hammerman",72000)
song[song.length]=new Array("http://www.tvthemetunes.net/_tv/b/bstar.wav","Bravestar",67000)
function init(){
index = Math.floor(Math.random() * song.length)
//index=0 //
change()
}
function change(){
stopped=0
clearTimeout(timer);
if(index==song.length){
index=0;
document.all.track.src = song[0][0]
}
else{
document.all.track.src = song[index][0]
}
window.status="PlayList ---- > Track "+(index+1)+" of "+song.length+" <<< "+song[index][1].substring(song[index][1].length,0)+" >>>"
if(loadnum<song.length{ // if played for first time add download time to play time
next=song[index][2]+loadtime
loadnum++
index++
timer=setTimeout("change()",next)}
}
}
function stop(){
if(stopped==1){return}
stopped=1
clearTimeout(timer);
index=index-1
document.all.track.src =""
windows.status="Player Stopped"
}
setTimeout("init()",2000)
//-->
</SCRIPT>
<BGSOUND SCR="" ID="track" VOLUME="80">
</html>
and
<HTML>
<SCRIPT language=JavaScript>
timer=""
a = 0
time = new array()
time[time.length] = 73000
time[time.length] = 33000
time[time.length] = 32000
time[time.length] = 17000
time[time.length] = 72000
time[time.length] = 67000
function init(){
a = Math.floor(Math.random() * document.embeds.length)
change()
}
function change (){
clearTiemout(timer);
if(a==document.embeds.length){
a=0;
documents.all.track.src = document.embeds[0].src
}
document.all.track.src = document.embeds[a].src
windows.status="Track "+(a+1)+" of "+document.embeds.length+" <<<"+document.embeds
[a].src.substring(document.embeds[a].src.length-4,0+" >>>"
timer=setTimeout("change()",time[a]);
a++
}
)
function stop(){
clearTimeout(timer);
a=a-1;
document.all.track.src =""
window.status="Player Stopped"
}
setTimeout("init()",2000)
//-->
</SCRIPT>
</HEAD><BODY>
<EMBED src=http://www.necrosdomain.co.uk/downloads/tvthemes/gadget.wav hidden=true loop="false" autostart="false" width="1" height="1" mastersound>
<EMBED src=http://www.necrosdomain.co.uk/downloads/tvthemes/dangermo.wav true loop="false" autostart="false" width="1" height="1" mastersound>
<EMBED src=http://www.tvthemetunes.net/_tv/b/buttonm.wav hidden=true loop="false" autostart="false" width="1" height="1" mastersound>
<EMBED src=http://www.tvthemetunes.net/_tv/b/bodgbadg.mp3 hidden=true loop="false" autostart="false" width="1" height="1" mastersound>
<EMBED src=http://www.trenchman.com/sounds/hammer.wav hidden=true loop="false" autostart="false" width="1" height="1" mastersound>
<EMBED src=http://www.tvthemetunes.net/_tv/b/bstar.wav hidden=true loop="false" autostart="false" width="1" height="1" mastersound>
<BGSOUND SRC="" ID="track" VOLUME="0"><!-- || -3000 to 0 || -->
</BODY></HTML>
troubleshooting on either would be fantastic if anyone can.
Thanks
Spamfritter
chrismiceli
12-20-2002, 11:21 PM
using this
if 1.wav = 5 secs
and 2.wav = 3 secs
and 3.wav = 7 secs
and i want a 1 sec pause between them
you could use timeouts
function wait() {
test = setTimeOut("document.embeds[1].play()", 6000);
test0 = setTimeOut("document.embeds[2].play()", 4000);
test1 = setTimeOut("document.embeds[3].play()", 8000);
if (loop) { //assign loop to true if you want to loop throug the songs
document.embeds[0[.play()
}
}
try that, i usually don't use sounds.
spamfritter
12-20-2002, 11:21 PM
ignore this, I messed up
chrismiceli
12-20-2002, 11:24 PM
java can be used on the web as applets or stand alone programs, mostly used for the former.
javascript named that way because netscape and sun were friends at the time (and could still be for all i know) is a web based client side programming language.
spamfritter
12-20-2002, 11:26 PM
Originally posted by chrismiceli
using this
if 1.wav = 5 secs
and 2.wav = 3 secs
and 3.wav = 7 secs
and i want a 1 sec pause between them
you could use timeouts
function wait() {
test = setTimeOut("document.embeds[1].play()", 6000);
test0 = setTimeOut("document.embeds[2].play()", 4000);
test1 = setTimeOut("document.embeds[3].play()", 8000);
if (loop) { //assign loop to true if you want to loop throug the songs
document.embeds[0[.play()
}
}
try that, i usually don't use sounds.
How would I try that, with urls not files, as a real newbie this seems like a deep end with sharks and custard in.
AAAARRRRGGGGHHHH!!
I think I'll go insane over this one
All so I'm in on fit sate to think about it now as I've had quite a bit of mullled wine *slurps even more* so I'll see if anyone has any anwsers tomorrwo.
Merry (litterally) Christmas
Spamfritter
spamfritter
12-20-2002, 11:30 PM
Originally posted by chrismiceli
java can be used on the web as applets or stand alone programs, mostly used for the former.
javascript named that way because netscape and sun were friends at the time (and could still be for all i know) is a web based client side programming language.
That's why I can do very basic Java but JavaScript is a complete mystery to me is it??
(and the fact that I used a very user orientated Java program instead of a true coder i supppose, i wish i could remember the program but i've lost the disk and it was a long time ago)
Spamfritter
zoobie
12-21-2002, 05:39 AM
Umm...I think I already answered this. First of all...they're all wav's and your visitor will wait 20 minutes per song to d/l. Like I said before...You're not going to be able to leach off other sites...The best you could do is take a small sample with the editor I already mentioned and string together a small set to be played as a single mp3 :rolleyes:
PS - loadtime = 2500 // time allowed for downloading? http://geocities.com/zoobie007/rotflmao.txt
Better change that to 25000000000000000000000000000 http://geocities.com/zoobie007/grin.txt
spamfritter
12-21-2002, 11:03 AM
I always think unrealistically about download times cos I'm connected to the web via an ADSL router :D. All the same I know most of the people viewing this and nearly all of them are on uni campuses and so will be on broadband like myself.
Those without broadband will have a choice not to play it via a broadband/dial-up choice, one whih links to page with music, one which links to same page without music.
Sorry I forgot to mention it.
Spamfritter
spamfritter
You may not know a lot about Javascript, but found it easy to take out my credits...WHY!!!
A lot of my brain cells died creating those scripts, don't let them have died in vain
PUT MY CREDITS BACK IN
PS
you messed to code up
try this
krycek
12-21-2002, 11:23 PM
Originally posted by Mr J
spamfritter
You may not know a lot about Javascript, but found it easy to take out my credits...WHY!!!
A lot of my brain cells died creating those scripts, don't let them have died in vain
PUT MY CREDITS BACK IN
...eh? what credits?
did I miss something here? :confused: I didn't see any credits in any of the code posted!
::] krycek [::
Thats because they've been taken out :D
joeframbach
12-22-2002, 07:12 PM
i like the music, really!
zoobie
12-22-2002, 07:53 PM
http://geocities.com/zoobie007/rotflmao.txt
spamfritter
12-23-2002, 09:53 AM
Sorry Mr J, I tried to copy and paste but my system crashed (I tried 3 times) when I tried to copy and paste. So I typed the whole lot out again with the two windows side by side. I just tried to edit them in again but the forum won't let me, I'm very sorry for this.
These are Mr J's script's and to the best of my knowledge they are very good ones, I will add them to the finished (if it ever does) page.
My sincere apologies but when typing it out again I tried to save time.
Sorry and Happy Christmas
Spamfritter
COOL ;)
And a merry Christmas to you all :D
:D
:D
:D
:D
:thumbsup:
Just in case here is the file again
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.