Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   [Javascript/HTML] Random Music Player (https://thetfp.com/tfp/tilted-technology/85079-javascript-html-random-music-player.html)

CityOfAngels 03-10-2005 01:06 AM

[Javascript/HTML] Random Music Player
 
Hi. I'd like to know how to program a random music player that would work on any standard web browser. Here is the code I have so far:
Code:

<html>
<body>

<h2>NAME OF SONG</h2>

<object
height="50%"
width="50%"
classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
<param name="AutoStart" value="0" />
<param name="FileName" value="URLtoSONG.wav" />
</object>

</body>
</html>

Now this is just basic HTML. I assume I need a Javascript, so this is what I need it to do:
1) I need it to work similar to the standard HTML code above as far as how user-friendly it is and how it is displayed.
2) I need either a random or sequential number within a range to be selected every time an external button (placed under the display, saying "Click here to change the song!") is clicked.
3) I need an "if" clause that aligns that range of numbers with URLs to different songs (which I will provide later), and then assigns them to the "FileName" value in the code above.
4) I also need the range of numbers to be assigned to the names of the songs, which will display in a label above the display.
5) If at all possible, it would also be cool if there can be a checkbox stuck next to the display that says "Autoplay?", and when checked, it would assign "AutoStart" value to "1", and when unchecked, it would assign that same value to "0".

Can anyone help me out with this? I've been wondering how to do this for quite some time. I've accomplished it in Visual Basic, but I have absolutely no experience with Javascript, and I haven't done any Visual Basic work at all for over 2 years.

CityOfAngels 03-18-2005 11:07 PM

I'd really appreciate it if someone could point me in the right direction here.

CityOfAngels 04-04-2005 09:03 AM

Anyone? Please?

CSflim 04-04-2005 01:22 PM

I have very little experience with javascript, and what little I did was quite a while ago, so there is certainly a more elegant way to do this, but here I go:

Code:

<HTML>
<BODY>

<SCRIPT>

num_of_songs = 3

randnum = Math.round(Math.random()*(num_of_songs-1)) + 1

if(randnum == 1){
        filename = "song1.wav";
        songname = "Name of first song";
}else if(randnum == 2){
        filename = "song2.wav";
        songname = "Name of second song";
}else if(randnum == 3){
        filename = "song3.wav";
        songname = "Name of thrd song";
}



document.write("<H2>");
document.write(songname);
document.write("<\H2>");

document.write("<object height=50% width=50% classid=clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95> <param name=AutoStart value=0 /> <param name=FileName value='");

document.write(filename);
document.write("'/></object>");

</SCRIPT>

<P>
<A HREF="javascript:history.go()">Click here to change track</A>

</BODY>
</HTML>


The "change track" link actually refreshes the page, causing a different random number to be picked. This might not be a very satisfactory way of doing it, but its a start at least.

Unfortunately, this method does not lend itself to easily implementing your "Autoplay" check box.


All times are GMT -8. The time now is 03:02 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43