View Full Version : music script?
hey,
i was just wondering if anyone knew a script to play music on a website, prefferably .wma
and a simple stop/play button for it
you can use something like
in the head
var musicsrc = "song.wav";
function playSounds () {
document.all("music").src = musicsrc;
}
function stopSounds () {
document.all("music").src="";
}
in the body
<body>
<bgsound src="" id="music">
<input type="button" onClick="playSounds();" value="Play">
<input type="button" onClick="stopSounds();" value="Stop">
Not sure if the syntax is exact, but it's something to start with.
ahhhh cool. thats great. but how would i move the buttons to somewhere else?
wait... umm.. its not working. it doesnt play... =\
umm.. i still cant get it to play a .wma
can anyone help :(
patrick
04-01-2003, 06:36 AM
There are two music scripts on this thread. I don't know if it also plays .wma
http://www.codingforums.com/showthread.php?threadid=17284
yea...i still cant get it to work... :(
someone plz help.
so far i've gotten this :
<a href="song.wma" autostart=true repeat=true loop=true ><img src=images/PLAY.gif></a>
but that code seems to make u have to d/l the song and it plays off winamp... i want it to play straight off my site :rolleyes:
and another one that im using now is:
<embed src="song.wma" width=25 height=25 autostart=true repeat=true loop=true>
but i wanna customize the button... but embed is the only way i see to actually play it off my site
:(
Try the following
<SCRIPT language=JavaScript type=text/javascript>
<!--
function preview(){
document.track.Play()
}
function Stop(){
document.track.Stop()
}
// -->
</script>
<EMBED SRC="song.wma" name="track" autostart="false" hidden="true"></EMBED>
<P><center>
<form>
<input type="button" onclick="Stop()" value="Stop">
<input type="button" onclick="preview()" value="Play">
</center>
Change song.wma for your file
thx.! thats awesome.
but is there anyway i can customize the button(using my own gif)? instead of using the IE button.
and i was wondering if there was a way to play more than 1 song.
for example:
:button: :button: :button:
:stop:
sorry if its a bad example :p
but yea, if i hit play on one. then it would stop the other, and play a different .wma, and same with the other :button:'s so it would have 3 different songs to choose from.
thx again though.! :thumbsup:
Have a play with the following:
There are 2 methods for using images
1) Use the image input
2) Use CSS
I have given you both example so you can see the difference.
Change the images to your own and the sound files as well.
<SCRIPT language=JavaScript type=text/javascript>
<!--
my_song=new Array()
my_song[0]="song1.wma" // first
my_song[1]="song2.wma" // second
my_song[2]="song3.wma" // third
function preview(n){
document.all.track.src=my_song[n]
}
function Stop(){
document.all.track.src =""
}
// -->
</script>
<BGSOUND SRC="" ID="track" VOLUME="0">
<P><center>
<form>
<input type="image" src="pic1.jpg" onclick="Stop();return false" value="Stop">
<input type="image" src="pic2.jpg" onclick=" preview(0);return false" value="Play 1">
<input type="image" src="pic3.jpg" onclick="preview(1);return false" value="Play 2">
<input type="image" src="pic4.jpg" onclick="preview(2);return false" value="Play 3">
<P>
<input type="button" onclick="Stop()" value="Stop" style="background-image:url(pic1.jpg); width:100; height:30">
<input type="button" onclick="preview(0)" value="Play 1" style="background-image:url(pic2.jpg); width:100; height:30">
<input type="button" onclick="preview(1)" value="Play 2" style="background-image:url(pic3.jpg); width:100; height:30">
<input type="button" onclick="preview(2)" value="Play 3" style="background-image:url(pic4.jpg); width:100; height:30">
</form>
</center>
awww. sweet thx.! thats exactly what i wanted :p :thumbsup:
but one question. how do i add autostart on it?:o
make it start when he page loads.
thx again. :D
Add
onload="preview(n)"
to the opening BODY tag
where n is the number relating to the my_song index of the song that you want to play onload
:thumbsup:
awesome man.!
cant thank you enuf :thumbsup: :D
johnwhite
09-12-2006, 03:31 PM
hi there,
i had been searching for what seems like an age before i found this topic - great, fantastically useful for a non techie like me. i have all up and working, have a look if you like at:
http://www.jrwpro.co.uk/soundtest/test7.htm
the sound files i have used are reasonably large, i am working on a preloader and will probably swap them for something smaller anyway which brings me to the question...
is there any way of making whichever file is being played (including the one which begins automatically as the page loads) loop continuously instead of just playing once?
many thanks in advance of your greatly appreciated help.
John
Add
LOOP=TRUE
to the embed, see if that works
johnwhite
09-13-2006, 05:45 PM
Hi Mr J,
thanks for the advice but i'm really not sure how to implement. i don't think the solution i'm using uses an embed feature.
here's the full code for the page:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT language=JavaScript type=text/javascript>
<!--
my_song=new Array()
my_song[0]="dkintro1.wav" // first
my_song[1]="shark.wav" // second
my_song[2]="beware_i.wav" // third
function preview(n){
document.all.track.src=my_song[n]
}
function Stop(){
document.all.track.src =""
}
// -->
</script>
</head>
<body onload="preview(0)">
<BGSOUND SRC="" ID="track" VOLUME="0">
<P><center>
<form>
<input type="image" src="stop.jpg" onclick="Stop();return false" value="Stop">
<input type="image" src="track1.jpg" onclick="preview(0);return false" value="Play 1">
<input type="image" src="track2.jpg" onclick="preview(1);return false" value="Play 2">
<input type="image" src="track3.jpg" onclick="preview(2);return false" value="Play 3">
</form>
</center>
</body>
</html>
i've changed the sound loops to something much smaller so it's way easier to see if they loop or not.
thanks for any help offered!
John
johnwhite
09-29-2006, 01:39 PM
*bump* could somebody help... please....
thanks,
John
ShadeSlayer
10-01-2006, 03:24 AM
Why dont you just embed the file?
Hello, this is my first post :) and I would like to use this code--it's working great. But I wonder if there is a way for when the page loads to have the songs start playing one after the other automatically and then loop. Then this would stop when the user either clicks "stop" or chooses to play a particular song.
Thanks in advance!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.