PDA

View Full Version : mp3 player controlled by php variable


rajo
04-08-2004, 10:27 PM
Hello, I am trying to set up a dynamic, streaming mp3 player for my site. I basically want to have someone click a url on the page with a php variable tagged on the end of it looking something like this <a href="#?track=trackname"> and have that feed into a swf on the same page. The variable will tell the swf which mp3 to load and stream. Ideally I would like to have the variable control what playlist is loaded via xml so it would be easier to change/add mp3s later. I just wanted to know if anyone could give me some pointers or resources to how I should go about doing this and if this method is logical. Just to clarify, I wanted to do this using said method because the site I am creating is controlled by a php cms which shows track listings on a dynamically generated page. I wanted to use a swf to play the mp3s not only to load them on the same page but also to make it harder fro people to download the file. Okay, sorry for the long explanation, thank you in advance.

Billy T
04-08-2004, 10:36 PM
echo the query var into the FLASHVARS

do a search for FLASHVARS - its easy

cheers

rajo
04-09-2004, 03:46 AM
Thanks, I am a little rusty with my action scripting as I have not used flash since version 5 really. I seem to be having some problems and I am not sure if I am coding this correctly. I have on my php page in an object tag

<embed src="../swf/mp3_player.swf" width="100" height="40" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" FlashVars="trackname=<?php echo "$track"; ?>"></embed>

and in my swf file I have dynamic text field with the variable name "mp3" in a movie clip. I have an instance of this mc on my main stage with this on clip event AS

onClipEvent (load) {
loadVariables("pathtomyurl", this, "GET");
if (trackname=seriousjoint) {
mp3.loadSound("pathtomyurl", true)
mp3.start(0, 1)
}
}

Sorry for my newbie questions here, I am just trying to piece together bits of tutorials/examples in my script so any help I can get would be great. Thanks in advance.

Billy T
04-09-2004, 04:51 AM
well I'm not really sure what you are trying to do

when you use FLASHVARS the variables you specify are created on _root, so your if statement should probably look more like

if (_root.trackname=='seriousjoint') {

dont forget the ==

what is seriousjoint?

what are you doing with the loadVariables ?

rajo
04-09-2004, 05:21 AM
sorry, seriousjoint is just the song title of the mp3 I am loading, I'm using it as the variable name for test purposes. Since I last posted I was able to successfully pass the variable to the swf, I took out loadvariables and put the if statement with loadsound and start sound commands on the first frame of the swf. It was loading the mp3 locally on my machine but not on my remote server. However this probably shouldn't have worked since no variable was loaded fro trackname. Thank you for advice, I'm sure that's where I went wrong.

rajo
04-10-2004, 05:12 PM
okay, I have my php variable passing correctly, and I can load id3 tags/start and stop the mp3 and I have a dynamic preloader. However, right now my variable, 'trackname' right now is being checked against a series of if else statements to figure out which mp3 file to load. I was wondering if there was a way for me to store the song url's in an xml file and somehow access the correct url node based on the variable sent to the loadSound function in my swf? Thanks to anyone who can help me in advance.

Billy T
04-18-2004, 10:09 AM
well if your flashvars has something like

track=bob_plays_guitar

then your loadSound would just look like

mySound.loadSound(track+'.mp3',true);