/    Sign up×
Community /Pin to ProfileBookmark

Calculate Mp3 Song Duration

I want to make a simple script that will return the duration in the format mm:ss. My host does not support the id3 functions in php, even though I am running php 5.

I know the mp3’s bitrate, which is 64kbps, but the math that I tried doesn’t seem to work very accurately. Also, not all of the mp3’s are tagged the same, some have image tags, others don’t. I don’t know if this would attribute to the filesize, but I’m thinking it does.

[code=php]
$path = ‘song.mp3’;
$bytes = filesize($path);
$bits = $bytes * 8;
$krate = 64;
$brate = $krate * 1024;
$seconds = $bits / $brate;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
echo $minutes . ‘:’ . round($seconds,0);[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@munjaldeveloperMay 10.2008 — If u find the solution of find the duration of the particular song, then please send it to me so that i can implement this in my code ...

Its urgent...?

? ? ?
Copy linkTweet thisAlerts:
@andre4s_yMay 10.2008 — Same solution :

Take a trip at http://getid3.org

@munjaldeveloper :

sorry if this does not help you..
Copy linkTweet thisAlerts:
@munjaldeveloperMay 10.2008 — The getid3 code of the site os not working properly..

means this one neither showing any error message nor the result...

What is the solution for this....

plz reply me as soon as possible....

Thanks in advance....

?
×

Success!

Help @rcracingfan24 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...