# Flash-\>PHP-\>flash (getting MP3's duration)

**URL:** <https://forum.kirupa.com/t/flash-php-flash-getting-mp3s-duration/202434>\
**Category:** Uncategorized\
**Created:** [October 1, 2006, 8:37am UTC](https://forum.kirupa.com/t/flash-php-flash-getting-mp3s-duration/202434 "2006-10-01T08:37:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Almonimus](https://avatars.discourse-cdn.com/v4/letter/a/b782af/32.png) [@Almonimus](https://forum.kirupa.com/u/Almonimus)\
**Post date:** [October 1, 2006, 8:37am UTC](https://forum.kirupa.com/t/flash-php-flash-getting-mp3s-duration/202434/1 "2006-10-01T08:37:06Z")

</div>

I’m building myself a flash site, and I need to get the duration of a song while being loaded. usind mp3file.duration while loaded gives the loaded segment duration and not the whole file, and getting to the id3 tag via flash is possible only when downloading is finished.

So, I want the flash sending a URL parameter (containning folders like “tracks/alternative/mymusic.mp3”) to this PHP file and getting back the duration.

I don’t know PHP and only recently I started struggling with action script. Does anyone know what’s the code I need to put in the PHP and how I make the flash communicate with it?

— Edit: I got help —

using [getID3](http://getid3.sourceforge.net/) and the following code in a PHP file:

\<?php  
require\_once(‘getid3/getid3.php’);  
$getID3 = new getID3;  
$ThisFileInfo = $getID3-\>analyze($\_GET[“filename”]);  
echo “\<XML\>”.$ThisFileInfo[‘playtime\_seconds’]."\</XML\>";  
?\>

Then calling it by:

```auto
function getDuration():Void {
    durationXML = new XML();
    durationXML.ignoreWhite = true;
    durationXML.load("duration.php?filename=" + run_url);
    durationXML.onLoad = function() {
        xml_duration = (durationXML.firstChild.firstChild.nodeValue);
        run_duration = (parseFloat(xml_duration));
        durationLoaded = true;
    }
}

```

This will put the duration of a “folder/file.mp3” in the var run\_duration.

I hope it’ll help others as it helped me 🙂
