alwaysinit Posted December 22, 2006 Share Posted December 22, 2006 I'm constructing an Mp3 player for my site that is fed it's songlist dynamically through the xml.php. All I need in the script is a way to get the 'filesize' and 'duration' from the songs, and output them in the XML rendering section of the PHP file.I was just wondering if it is possible to do this with a few lines of code, rather than implement a whole ID3 class into my script. I don't yet know enough to rip the classes apart and take the functions that I need out. So if anyone here may have a no nonsense, lightweight approach for me, I would love to see it and try it out. The urls where the physical MP3 files reside are listed in the script here.I placed ?????? in the XML area for the 'filesize'&'duration' variables.Many thanks to responders. xml.php[code]<?phpsession_start(); header("Cache-control: private"); if (!$_SESSION['email']) { echo "You aren't logged in."; exit(); } echo "<?xml version=\"1.0\"?>\n";echo "<songs>\n";echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_1'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . $_SESSION['????????'] . "' url='../user_files/song1/" . $_SESSION['song_1'] . "' />\n";echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_2'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . $_SESSION['????????'] . "' url='../user_files/song2/" . $_SESSION['song_2'] . "' />\n";echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_3'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . $_SESSION['????????'] . "' url='../user_files/song3/" . $_SESSION['song_3'] . "' />\n"; echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_4'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . $_SESSION['????????'] . "' url='../user_files/song4/" . $_SESSION['song_4'] . "' />\n";echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_5'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . $_SESSION['????????'] . "' url='../user_files/song5/" . $_SESSION['song_5'] . "' />\n";echo "</songs>\n";?>[/code]And this is the XML it renders:[code] <?xml version="1.0" ?> - <songs> <song artist="Allison" title="Midnight Ride" duration="???????" filesize="???????" url="../user_files/song1/16.mp3" /> <song artist="Allison" title="Almost Me Again" duration="???????" filesize="???????" url="../user_files/song2/16.mp3" /> <song artist="Allison" title="Hope you Live" duration="???????" filesize="???????" url="../user_files/song3/16.mp3" /> <song artist="Allison" title="Midnight Ride" duration="???????" filesize="???????" url="../user_files/song4/16.mp3" /> <song artist="Allison" title="punched a hole in it" duration="???????" filesize="???????" url="../user_files/song5/16.mp3" /> </songs>[/code]The member's various mp3s all have the same name, just spread to 5 different folders.Thanks Quote Link to comment Share on other sites More sharing options...
taith Posted December 22, 2006 Share Posted December 22, 2006 [code]filesize($filename)[/code] Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted December 22, 2006 Author Share Posted December 22, 2006 ThanksLike this?[code]echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_1'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . $_SESSION['filesize($filename)'] . "' url='../user_files/song1/" . $_SESSION['song_1'] . "' />\n";[/code] Quote Link to comment Share on other sites More sharing options...
taith Posted December 22, 2006 Share Posted December 22, 2006 no... thats inside out ;-)[code]echo "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_1'] . "' duration='" . $_SESSION['????????'] . "' filesize='" . filesize($_SESSION['filepath']) . "' url='../user_files/song1/" . $_SESSION['song_1'] . "' />\n";[/code] Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted December 22, 2006 Author Share Posted December 22, 2006 :oCan't see your code, oh no! lolnevermind, just looked in firefox, I see your code. I'll try it out thanks Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted December 22, 2006 Author Share Posted December 22, 2006 So I need to $filepath = "../user_files/song1/" . $_SESSION['song_1']";before starting the XML creation for that to work right?Any thoughts on the song duration aspect? Quote Link to comment Share on other sites More sharing options...
alwaysinit Posted December 23, 2006 Author Share Posted December 23, 2006 OK, here is the solution I created for finding MP3 file sizes(tried a few different file types, and they all worked txt,php,html)[code]<?php// this line puts the file into variable($filename) from it's url location$filename = '../../user_files/song3/' . $_SESSION['song_3'] . '';// XML renderingecho "<song artist='" . $_SESSION['username'] . "' title='" . $_SESSION['songtitle_1'] . "' duration='" . $_SESSION['song1time'] . "' filesize='" . filesize($filename) . "' url='../user_files/song1/" . $_SESSION['song_1'] . "' />\n";?>[/code]Now that that's out of the way, does anybody know how to determine MP3 "duration" or "playtime"? It is the last bit of coding I need for the player.Would it work in the same fashion as filesize? I'll go lookin' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.