MP3 error

The place for "I can't figure out how to..." questions.
Post Reply
musicweb
User
Posts: 5
Joined: Thu Sep 03, 2015 3:24 pm
Are you a spambot?: no

MP3 error

Post by musicweb » Thu Sep 03, 2015 3:31 pm

Trying to use this code to extract a 30 second mp3 demo for our website.
The mp3 file is valid.
When we run the code, it gives an error:
"video can't be played because the file is corrupt"
Do we need to configure getid3.php to read mp3 files first?

Here's our code:

Code: Select all

 
<?php
 $filename = "/home/bruce/public_html/cat/system/download/ge229/ge229_together.mp3";
 
 require_once('/usr/share/php/getid3/getid3.php');
 $getID3 = new getID3();  
      
    $id3_info = $getID3->analyze($filename);  
      
    list($t_min, $t_sec) = explode(':', $id3_info['length']);  
    $time = ($t_min * 60) + $t_sec;  
      
    $preview = $time / 30; // Preview time of 30 seconds  
      
    $handle = fopen($filename, 'r');  
    $content = fread($handle, filesize($filename));  
      
    $length = strlen($content);  
      
 //   if (!$session->IsLoggedIn()) {  
        $length = round(strlen($content) / $preview);  
        $content = substr($content, $length * .66 /* Start extraction ~20 seconds in */, $length);  
 //   }  
      
    header("Content-Type: {$id3_info['mime_type']}");  
    header("Content-Length: {$length}");  
    print $content;  
These errors also show up in the server logs:
  • [Thu Sep 03 11:20:25.607295 2015] [:error] [pid 4938] [client 70.188.133.169:65287] PHP Notice: Undefined index: length in /home/bruce/public_html/cat/mp3demo.php on line 9
    [Thu Sep 03 11:20:25.607365 2015] [:error] [pid 4938] [client 70.188.133.169:65287] PHP Notice: Undefined offset: 1 in /home/bruce/public_html/cat/mp3demo.php on line 9
    [Thu Sep 03 11:20:25.610158 2015] [:error] [pid 4938] [client 70.188.133.169:65287] PHP Warning: Division by zero in /home/bruce/public_html/cat/mp3demo.php on line 20

James Heinrich
getID3() v1 developer
Posts: 1421
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: MP3 error

Post by James Heinrich » Sat Sep 05, 2015 2:17 pm

First thing that jumps out at me:

$id3_info['length'] is not a key that I would expect to see returned by getID3:analyze -- you should be using $id3_info['playtime'] which will return the length of the file in decimal seconds, there is no need for you to parse and recreate it from minutes and seconds as you're doing. If you do need a hour:minute:second type string for display it is available in $id3_info['playtime_string'] but for any calculations you should just use the provided seconds in $id3_info['playtime']

musicweb
User
Posts: 5
Joined: Thu Sep 03, 2015 3:24 pm
Are you a spambot?: no

Re: MP3 error

Post by musicweb » Tue Sep 08, 2015 6:12 pm

Thanks James... I'll try that tonight.

musicweb
User
Posts: 5
Joined: Thu Sep 03, 2015 3:24 pm
Are you a spambot?: no

Re: MP3 error

Post by musicweb » Thu Sep 10, 2015 5:15 pm

still get the same errors with "playtime"
[Thu Sep 10 13:12:26.579826 2015] [:error] [pid 31976] [client 70.188.133.169:49821] PHP Notice: Undefined index: playtime in /home/bruce/public_html/cat/mp3demo.php on line 9
[Thu Sep 10 13:12:26.579889 2015] [:error] [pid 31976] [client 70.188.133.169:49821] PHP Notice: Undefined offset: 1 in /home/bruce/public_html/cat/mp3demo.php on line 9
[Thu Sep 10 13:12:26.582667 2015] [:error] [pid 31976] [client 70.188.133.169:49821] PHP Warning: Division by zero in /home/bruce/public_html/cat/mp3demo.php on line 20

James Heinrich
getID3() v1 developer
Posts: 1421
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: MP3 error

Post by James Heinrich » Thu Sep 10, 2015 6:13 pm

Well, do a print_r / var_dump on the array and see what you do have.
Also, you should be checking ['warning'] and ['error'] for error messages. Something in ['warning'] is usually OK, something in ['error'] means either the file failed to parse at all, or there's a serious problem and the returned data may be incomplete or incorrect.

musicweb
User
Posts: 5
Joined: Thu Sep 03, 2015 3:24 pm
Are you a spambot?: no

Re: MP3 error

Post by musicweb » Thu Sep 10, 2015 9:19 pm

I think I know what may be happening here.
We run a music site for independent artists out of Quebec.
The songs are taken from the artist CDs and probably don't
have all the info about the song embedded in them.
Most CDs are generated at the artist's own studios.
Not sure....

James Heinrich
getID3() v1 developer
Posts: 1421
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: MP3 error

Post by James Heinrich » Thu Sep 10, 2015 9:31 pm

That's not going to have anything to do with anything. The playtime of the MP3 file is completely unrelated to any metadata about artist/title/album/etc that may (or may not) exist in ID3v1/ID3v2/APE/Lyrics3 tags.

musicweb
User
Posts: 5
Joined: Thu Sep 03, 2015 3:24 pm
Are you a spambot?: no

Re: MP3 error

Post by musicweb » Fri Sep 11, 2015 11:38 am

Tried several other mp3 files and still same error.
Why does it say "video can't be played" when it's an mp3?

James Heinrich
getID3() v1 developer
Posts: 1421
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: MP3 error

Post by James Heinrich » Fri Sep 11, 2015 12:39 pm

Whatever is telling you that has nothing to do with getID3.
getID3 analyzes files and metadata, it does not attempt to play them in any way.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest