Seconds appends a millisecond

Seconds appends a millisecond

Postby melino » Tue Sep 20, 2011 6:35 pm

The playtime of some mp3s are most times put out correct like 3:29.
On some mp3s getID3 appends a millisecond, so 3:295.

Why? How can I get rid of this?
Thanx! :-)
melino
User
 
Posts: 5
Joined: Tue Sep 20, 2011 6:29 pm

Re: Seconds appends a millisecond

Postby James Heinrich » Tue Sep 20, 2011 9:03 pm

Are you using [playtime] or [playtime_string]?
What version of getID3 are you using?
Please post or PM me a link to a sample file that shows this problem.
James Heinrich
getID3() v1 developer
 
Posts: 1203
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Re: Seconds appends a millisecond

Postby melino » Wed Nov 02, 2011 5:01 pm

Sorry for not getting back. I forgot to subscribe so I wasn't knowing anyone answered.
I'll send you a PM now, the website is not public.
melino
User
 
Posts: 5
Joined: Tue Sep 20, 2011 6:29 pm

Re: Seconds appends a millisecond

Postby James Heinrich » Thu Nov 03, 2011 8:23 am

You'll need to double-check your code. Using provided sample file, your site displays "5:047". getID3 returns: [playtime_string]=>'5:47', [playtime_seconds]=>'347.2457'.
Looking at a sample of playtimes on your site (4:05, 3:09, 5:018, 3:023, 3:038, 3:45, 5:047, 4:048) I don't see any particular pattern as to where or why your playtime is padded with an extra '0'.
The returned 'playtime_string' value should be used directly, it already has the seconds padded as needed; for long files it will also display hours and have the minutes field padded if needed.
Please confirm which version of getID3 you're using?
James Heinrich
getID3() v1 developer
 
Posts: 1203
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Re: Seconds appends a millisecond

Postby melino » Thu Nov 03, 2011 8:59 am

Thanks for this helpful hint. The codes is the same on all tracks. But I found out that the error depends on the mp3 it uses. If I use track 1 for the track that causes 5:074 it is correctly 3:45. Same for all others.
But I can't find the different of the mp3s. All will look further later.


The version of getID3 is the latest 1.9.1.
melino
User
 
Posts: 5
Joined: Tue Sep 20, 2011 6:29 pm

Re: Seconds appends a millisecond

Postby James Heinrich » Thu Nov 03, 2011 9:34 am

If you can't figure it out for whatever reason, post the code that displays the time and I'll see if I can spot what's going wrong.
James Heinrich
getID3() v1 developer
 
Posts: 1203
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Re: Seconds appends a millisecond

Postby melino » Thu Nov 03, 2011 10:59 am

I PMed you the PHP file yesterday. Anyway here is the code:

Code: Select all
<?php
require_once('js/getid3/getid3.php');
$url=$TrackFileHere.'.mp3';
if($url){
$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents($url, false, null, 0, 300000))) {
   if (require_once('js/getid3/getid3.php')) {
      $getID3 = new getID3;
      $ThisFileInfo = $getID3->analyze($filename);}
   unlink($filename);}}
$bitratez=$ThisFileInfo[audio][bitrate];
$headers = get_headers($url, 1);
            if ((!array_key_exists("Content-Length", $headers))) { return false; }
            $filesize= round($headers["Content-Length"]/1000);
$contentLengthKBITS=$filesize*8;
$bitrate=$bitratez/1000;
$seconds=$contentLengthKBITS/$bitrate;
$playtime_mins = floor($seconds/60);
$playtime_secs = $seconds % 60;
if(strlen($playtime_secs)=='1'){$zero='0';}
$playtime_secs = $zero.$playtime_secs;
$playtime_string=$playtime_mins.':'.$playtime_secs;
echo $playtime_string;
?>
      </td>
      <td><?php echo($TrackISRCHere); ?></td>
      <td style="text-align: center; font-weight: bold;"><a href="<?php echo($TrackFileHere)?>.mp3">mp3</a>
/ <a href="<?php echo($TrackFileHere)?>.wav">wav</a></td>
    </tr>
<?php
    }
?>
melino
User
 
Posts: 5
Joined: Tue Sep 20, 2011 6:29 pm

Re: Seconds appends a millisecond

Postby James Heinrich » Thu Nov 03, 2011 11:07 am

melino wrote:
Code: Select all
$headers = get_headers($url, 1);
            if ((!array_key_exists("Content-Length", $headers))) { return false; }
            $filesize= round($headers["Content-Length"]/1000);
$contentLengthKBITS=$filesize*8;
$bitrate=$bitratez/1000;
$seconds=$contentLengthKBITS/$bitrate;
$playtime_mins = floor($seconds/60);
$playtime_secs = $seconds % 60;
if(strlen($playtime_secs)=='1'){$zero='0';}
$playtime_secs = $zero.$playtime_secs;
$playtime_string=$playtime_mins.':'.$playtime_secs;
echo $playtime_string;
Take out all that, and replace it with:
Code: Select all
echo $ThisFileInfo['playtime_string'];
James Heinrich
getID3() v1 developer
 
Posts: 1203
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Re: Seconds appends a millisecond

Postby James Heinrich » Thu Nov 03, 2011 11:10 am

Ah, wait, I see why you're doing it that way, you're analyzing a small chunk of a remote file. In that case, replace this:
Code: Select all
$playtime_mins = floor($seconds/60);
$playtime_secs = $seconds % 60;
if(strlen($playtime_secs)=='1'){$zero='0';}
$playtime_secs = $zero.$playtime_secs;
$playtime_string=$playtime_mins.':'.$playtime_secs;
echo $playtime_string;
with this:
Code: Select all
echo getid3_lib::PlaytimeString($seconds);
James Heinrich
getID3() v1 developer
 
Posts: 1203
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Re: Seconds appends a millisecond

Postby melino » Thu Nov 03, 2011 1:56 pm

Fantastic! Worx. - Many thanks, James. :-))
melino
User
 
Posts: 5
Joined: Tue Sep 20, 2011 6:29 pm


Return to Support 1.x (resolved)

Who is online

Users browsing this forum: No registered users and 0 guests