Got a little techonology problem that you need fixed pronto? Post it here and we'll see what we can do.
Topic locked

Question About Adding Music to a Page

Sat Jun 12, 2004 8:29 pm

Hi, just a quick little question, and I'd appreciate any help.

Currently, I'm working on customizing my LiveJournal. I know that there are codes to add music to a page in HTML or CSS or whatever, and I know that you can make one song play infinitely. However, I was wondering if it was possible to play a few songs in a loop, something like this:

Song 1
Song 2
Song 3
Song 4
Song 1 again
etc.

Is there any codes to do this, and if so will you let me know what they are? Thanks! :D

Sat Jun 12, 2004 9:02 pm

Try using a media player control with a playlist.

I don't think you can do this with bgsound.

Sat Jun 12, 2004 11:10 pm

hmm good one, i knwo theres a way to do it try looking into some javascript, a couple tips:

maybe somehting like document.bgsound="thesound";

whihc might set the sound but dont count on it becaus eim only guessing

what iw ould do is make a function that recurse after a song is done, you might have to se tthe length of a song, ill look more into it for ya

Sun Jun 13, 2004 2:30 pm

That's another way to do it. If you setTimeout(handlerfunction, songlength*1000), you'll know when to set the next one.

Assuming document.bgsound is valid, you would use:
Code:
<script>
var songs = Array("sound1.mid","sound2.mid","sound3.mid"); //Filenames
var slength = Array(67,23,43); //Duration in seconds
var song_id = 0; //Start ID

nextSong();

function nextSong() {
 document.bgsound = songs[song_id];
 setTimeout ("nextSong();",slength[song_id]*1000);
 song_id++;
 if (song_id > songs.length) song_id = 0;
}
</script>
Topic locked