Jump to content

Can anyone show me how to display 'filesize' & 'duration' from my MP3s?


alwaysinit

Recommended Posts

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]
<?php
session_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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 rendering

echo "<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'
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.