Title: Coding Help
The Zombie - March 3, 2006 06:35 PM (GMT)
Alright, I know HaTcH or someone wrote the coding for the forum banners up top that randomly switch the banners around. I'm trying to the same, but with background music. So every time I got to a page I have background music playing, but its played at random and when each is finished it randomly selects another song to play afterwards, but doesn't change the song if you go to another page on the Aviation forums I'm running. I need some help with this, as I Suck at coding.
ZeRoRaVeN - March 3, 2006 11:04 PM (GMT)
That's because that image banner up there is meant for use with images. Firstly, let me tell you, playing music at random on a forum really isn't suggested, secondly, it's bandwidth consuming and unless you have a dedicated server with unlimited bandwidth, I really don't suggest linking to your own web host or stealing bandwidth.
| CODE |
<script type="text/javascript">
//Script by HaTcH 04-02-05 //To add a new banner to the list, increase TOTAL_BANNERS by 1 //and add a new line to the New Array definition
//This value is for the total number of images there are var TOTAL_BANNERS = 11;
//This is the array containing the urls. //You must include the entire http:// path. var urls = new Array( "http://i6.photobucket.com/albums/y225/zoids_evolution/Blade4.jpg", "http://i6.photobucket.com/albums/y225/zoids_evolution/Tilly1.gif");
//Selects a random number between 0 and the total number //of images less 1. var index = Math.round(Math.random()*(TOTAL_BANNERS-1));
document.write("<a href=\"http://s4.invisionfree.com/Zoids_Evolution/index.php?\" title=\"Board Home\"><img src=\"" + urls[index] + "\" alt=\"Welcome to Zoids Evolution Forums!\" title=\"Welcome to Zoids Evolution Forums!\"></a>");
</script> |
Let's see...yay! HaTcH used arrays...rawr!
Ok, I suggest you code a multidimensional array seeing as that array will be too small, and edit it.
Hmm...I do wonder how to do random with php...generate a random number as set a variable as that and then use if == 1, echo <banner> else if === 2 etc etc....
Capitila - March 4, 2006 03:09 AM (GMT)
http://webtips.dan.info/sounds.htmlIf the top part of the page doesn't put you off, it's fairly easy to implement with Hatch's code.
If you're still stuck with playing randomly you can do it a different way through a playlist file. Step by step instructions from -
http://www.boutell.com/newfaq/creating/randomsongs.html
HaTcH - March 4, 2006 04:33 AM (GMT)
Yes, basically use the same type of system, creating an array of urls to the midi files or whatever, picking a random index, and then throwing it inside an <embed> tag, instead of an <img> tag.
If you want the music to play as the same song on different pages, you'll need either javascript cookies or use php?var=data tags.
KSZ uses that sort of thing, when a user clicks the top banner, it reloads the page, but tacks on a "state=1" thing to the url. Then when the page is processed again, it displays a random quotation instead of the page's title.
I don't really know how to make it play more than 1 file, as I don't use <embed> like at all... IMO sites that have music =/= good sites. I either exit the page quickly or turn off the speakers.
The Zombie - March 4, 2006 04:03 PM (GMT)
Eh... *brain hurts*
Alright, but what did you mean about php?var=data tags?
HaTcH - March 4, 2006 06:01 PM (GMT)
Well its a method of passing variables via the URL instead of by form data.
Basically you do it like this.
Call a php script: foo.php
with the variable bar, and set bar's value to 5
foo.php?bar=5
Then inside foo.php, you can access bar by doing $_GET['bar'] which will return the value of bar.
ZeRoRaVeN - March 4, 2006 08:49 PM (GMT)
| QUOTE (HaTcH @ Mar 4 2006, 01:01 PM) |
Well its a method of passing variables via the URL instead of by form data.
Basically you do it like this.
Call a php script: foo.php with the variable bar, and set bar's value to 5 foo.php?bar=5
Then inside foo.php, you can access bar by doing $_GET['bar'] which will return the value of bar. |
Don't listen to him! It's not actually random!
I can't believe you're serious about doing +1 though the GET method. Besides POST is better, but you can't do the same with POST since the information isn't parsed though the browser's URL. Way too insecure GET is, but we're not trying to be secure are we?
What if....you generate a random value mathmatically, and set the variable as something like $random then do something similiar:
| CODE |
<?php //random code $random = rand(1, 3);
//rawr! play the file depending on what you want. if ($random == '1'); } echo '<music player CODE 1>'; { else if ($random == '2'); } echo '<music okayer CODE 2>'; { else if ($anromd == '3'); } echo '<music okayer CODE 3>'; { //This isn't needed, just something in case you set the value too high and it gets generated else } echo 'waaa? It seems a random number got generated and it isn't defined!' { ?>
|
There, since IF doesn't allow PHP, simply host the file on a seperate server with php support and use a iframe to get it.
EDIT: Oops, I forgot that gmp_random does it from 0 to whatever number you set.
EDIT2: Sorry, gmp_random doesn't generate a random number, it does generate something random, but a string of it, instead use rand.
Note that some systems set limits on the rand number you can go up to. You can bypass that though min and max you can create a larger range of RAND_MAX. But the limit is large anyway. So you shouldn't need to worry about it.
HaTcH - March 4, 2006 11:36 PM (GMT)
Why not do this: on the entrance page, generate an N digit/letter number. Where N refers to the number of songs in your playlist.
Bear with me on this..
Generate this string which could be passed via GET or POST, however you want, and then each page that actually plays the music in the order of the generated session number.. For example. (eg):
You have 10 different songs. numbers 0-9 (of you have more extend to alpha, 0-9a-z)
Visitor visits page
-->visitor is given key 05631897432.
Now on the content pages, the first song that will play would be 0, followed by 5, followed by 6 and so on.. If you're lucky and the user actually sticks around your site long enough with annoying music, then the random patter could be re-written.
@Zero, you dont have to use an iframe to get php script capability. Ever hear of the javascript trick?
| CODE |
<script language="javascript" href="foo.php"> </script>
where foo is a link to another file which returns javascript code such as "document.write('<embed whatever-the-syntax-is>');"
|
Either that or you could just use frames. Create like an invisible frame on the front page and just load all your content inside that...
~If its so insecure, then why does invision use it??
| CODE |
| http://s4.invisionfree.com/Zoids_Evolution/index.php?act=Post&CODE=08&f=33&t=4296&p=10535618&st=0 |
I count about 6 variables there XD
The Zombie - March 6, 2006 04:35 PM (GMT)
>.< Okay, my brain is hurting... I don't know too much about coding and I'm going bonkers trying to figure out what you two are talking about. :D
ZeRoRaVeN - March 7, 2006 12:15 AM (GMT)
That code is for your posting, it's possible you had cookies enabled so the session wouldn't show in the URL.
What you're suggesting isn't random, he wants it random.
HaTcH - March 7, 2006 04:14 AM (GMT)
No, what he wants is a play list sort of thing. The only real way I could see this work would be with a frame. You can't really browse around a website and hope to have a random playlist that keeps playing right where it picked up.
You could generate a random playlist on the first visit to a frame using php (or even javascript) and then play the songs in that order inside the frame, enabling the user to browse around your website with the songs uninterrupted. Doing it anyother way is just overkill ZeRo. Have you got any ideas?
blackchaos13, if you can find information to play songs in succession with <embed> or some other thing like that, give me the link. I can write the program for you no sweat. ;) So yeah, playlists in HTML.. I'll make you a randomize program. I just dont feel like researching playlists.
The Zombie - March 7, 2006 04:26 PM (GMT)
Thanks HaTcH, but the only thing I know about is the jukebox thingy you find on the invisionfree forums in the code area.
HaTcH - March 7, 2006 05:36 PM (GMT)
All right then, (visited Capitila's links) I'll get to work on it tonight after work or tomorrow. ;)
ZeRoRaVeN - March 8, 2006 02:53 AM (GMT)
| QUOTE (blackchaos13 @ Mar 3 2006, 01:35 PM) |
| Alright, I know HaTcH or someone wrote the coding for the forum banners up top that randomly switch the banners around. I'm trying to the same, but with background music. So every time I got to a page I have background music playing, but its played at random and when each is finished it randomly selects another song to play afterwards, but doesn't change the song if you go to another page on the Aviation forums I'm running. I need some help with this, as I Suck at coding. |
That's the quote from his first post, and that's how I interpreted it as.