Page 1 of 2
flash mp3player
Posted: Fri Aug 15, 2008 2:51 am
by tom456
hi!
i recently made a mp3player(swf file) which plays different (mp3,..) songs..
player gets its musiclist from .txt file...
example of player is here:
http://www.hot.ee/antsman333
and the musiclist is located here:
http://hot.ee/antsman333/list.txt
and my question is following: i want to create a php script, which can modify the musiclist file with new songs.
the script should have different kind forms, like where can I put the song name, URL, picture URL etc...
(if the script changes the .txt file, then it doesnt overwrites the existing songs)
could somebody help me?
Re: flash mp3player
Posted: Fri Aug 15, 2008 11:34 am
by Christopher
Rather than making a PHP script that can modify the play list, make a PHP script that IS the play list. PHP is designed to generate scripts of different kinds. Just generate XML of whatever format the play list is.
Re: flash mp3player
Posted: Fri Aug 15, 2008 11:43 am
by tom456
arborint wrote:Rather than making a PHP script that can modify the play list, make a PHP script that IS the play list. PHP is designed to generate scripts of different kinds. Just generate XML of whatever format the play list is.
ok thanks, but im not able to do it by myself (im noob)

i havent learned any programming languages yet..
could you give me some advice how to make it (first steps etc)..

Re: flash mp3player
Posted: Fri Aug 15, 2008 1:09 pm
by Christopher
If the playlist was XML you could do something like this:
Code: Select all
$playlist = array(
1 => array(
'title' => 'Foo',
'filename' => 'foo.mp3',
),
2 => array(
'title' => 'Bar',
'filename' => 'bar.mp3',
),
);
$out = "<playlist>\n";
foreach ($playlist as $entry) {
$out .= " <entry>
<title>{$entry['title']}</title>
<filename>{$entry['filename']}</filename>
</entry>
";
}
$out .= "</playlist>\n";
echo $out;
Re: flash mp3player
Posted: Fri Aug 15, 2008 1:23 pm
by tom456
arborint wrote:If the playlist was XML you could do something like this:
Code: Select all
$playlist = array(
1 => array(
'title' => 'Foo',
'filename' => 'foo.mp3',
),
2 => array(
'title' => 'Bar',
'filename' => 'bar.mp3',
),
);
$out = "<playlist>\n";
foreach ($playlist as $entry) {
$out .= " <entry>
<title>{$entry['title']}</title>
<filename>{$entry['filename']}</filename>
</entry>
";
}
$out .= "</playlist>\n";
echo $out;
plz dont get mad, but could you explain it step-by-step.. im very n00b

Re: flash mp3player
Posted: Fri Aug 15, 2008 1:52 pm
by desmi
Code: Select all
//First we create an array ($playlist), and add some values to it
$playlist = array(
1 => array(
'title' => 'Foo',
'filename' => 'foo.mp3',
),
2 => array(
'title' => 'Bar',
'filename' => 'bar.mp3',
),
);
//Then we define output variable and start adding text to it
$out = "<playlist>\n";
// we add all $playlist array value to that same output variable ( this will loop as many times as there are values in array)
foreach ($playlist as $entry) {
$out .= " <entry>
<title>{$entry['title']}</title>
<filename>{$entry['filename']}</filename>
</entry>
";
}
//And finally we add the ending to that output
$out .= "</playlist>\n";
//And then we echo that whole output variable
echo $out;
And this is only a "hardcoded" example how you could do it, ofcourse you need the main script to add array values via form or something..
Re: flash mp3player
Posted: Fri Aug 15, 2008 2:29 pm
by Christopher
Yes, I am assuming that playlists would come from a database or something like that. This code is just to get an admitted beginner started. You might also want to wrap the playlist generator in a function or class to make it more reusable.
Re: flash mp3player
Posted: Fri Aug 15, 2008 2:50 pm
by tom456
Re: flash mp3player
Posted: Fri Aug 15, 2008 3:00 pm
by Christopher
If you want to write the playlist to a file then yes.
Re: flash mp3player
Posted: Fri Aug 15, 2008 4:20 pm
by tom456
arborint wrote:If you want to write the playlist to a file then yes.
ok thanks for answering
but could you help me to make this form (sorta "web-based playlist modifier") where can i simply write down song names, URLs etc and then save it to webserver..
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="0" xmlns="
http://xspf.org/ns/0/">
<title>MP3Player</title>
<creator>tom</creator>
<trackList>
<track>
<location>
http://hot.ee/antsman333/Nirvana-FreeBird.mp3</location>
<identifier>684088:Track:1639</identifier>
<title>Free bird</title>
<creator>Nirvana</creator>
<image>
http://g8.undercoverhd.com/imgsresized/ ... jpg</image>
<extension application="
http://docs.ning.com/music/">
</extension>
</track>
Re: flash mp3player
Posted: Fri Aug 15, 2008 4:47 pm
by Christopher
Just take what I posted above and try to generate a "trackList". You just need to edit it a little and add a couple fields. See what you get.
Re: flash mp3player
Posted: Fri Aug 15, 2008 4:59 pm
by tom456
arborint wrote:Just take what I posted above and try to generate a "trackList". You just need to edit it a little and add a couple fields. See what you get.
thanks!
ok i will try it on tomorrow
btw sry for disturbing you

Re: flash mp3player
Posted: Fri Aug 15, 2008 5:30 pm
by tom456
i found a php script which adds your written data into textfile, but it overwrites the exciting data...
but i dont want to owerwrite the data...
is it possible to change this script?
the script is located in this topic:
http://www.dynamicdrive.com/forums/arch ... -4539.html
plz help

Re: flash mp3player
Posted: Fri Aug 15, 2008 5:35 pm
by Christopher
I'd recommend that you look around in this section of the PHP manual:
http://us2.php.net/manual/en/book.filesystem.php
Especially the sections on the functions called in the examples you found, so you know what they do and what the parameters are. There is also a lot of example code in the manual and comments.
Re: flash mp3player
Posted: Fri Aug 15, 2008 5:45 pm
by tom456
arborint wrote:I'd recommend that you look around in this section of the PHP manual:
http://us2.php.net/manual/en/book.filesystem.php
Especially the sections on the functions called in the examples you found, so you know what they do and what the parameters are. There is also a lot of example code in the manual and comments.
i found the way how to rewrite the data in text file

here's the code:
<?
if($_POST['Submit']){
$open = fopen("textfile.txt","a+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("textfile.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("textfile.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>
but it doesnt leave any line spacing..
how to fix this problem?
