Function to return song duration

The place for "I can't figure out how to..." questions.
Post Reply
MarkF
User
Posts: 2
Joined: Tue May 29, 2007 11:44 am

Function to return song duration

Post by MarkF » Tue May 29, 2007 11:49 am

Hi guys, I'm trying to create a php function to return the duration of a given song

my code so far is as follows

function get_duration($trackpath, $track)
{
// include getID3() library
require_once('./getid3/getid3.php');
//or wherever getid3 is stored



$FullFileName = realpath($trackpath.'/'.$track);



if (is_file($FullFileName)) {
set_time_limit(30);

$ThisFileInfo = $getID3->analyze($FullFileName);

getid3_lib::CopyTagsToComments($ThisFileInfo);


// output desired information in whatever format you want
$duration = $ThisFileInfo['playtime_seconds'];

return $duration;
}
}

When run the function is run my code returns Fatal error: Call to a member function analyze() on a non-object in /var/www/nonstop/playlist.php on line 162 - I don't really understand this (I'm fairly new to php and i'm not totally sure what this means or how to fix it.

can anyone help me????

Allan Hansen
getID3() v2 developer
Posts: 445
Joined: Sun May 04, 2003 2:22 pm
Location: Holmegaard, Denmark

Post by Allan Hansen » Tue May 29, 2007 11:52 am

Check the simple/basic demos located in the demos/ directory.

This particular error means you forgot this line before analyze():

$getID3 = new getID3();

MarkF
User
Posts: 2
Joined: Tue May 29, 2007 11:44 am

Post by MarkF » Tue May 29, 2007 1:06 pm

Thankyou,

works a treat! :D

Post Reply