/** * analyze MP3 file, and return MP3 tag info * * @param [auto detect] a file path or a file object is acceptable * @return null or an array of MP3 info */ public function analyzeMp3($file_para = '') { // if no path specified, return 'null' if (empty($file_para)) { return null; } // we need file path for GetId3 $filepath = is_object($file_para) ? $file_para->getRealPath() : realpath($file_para); // initialize Id3 helper, and then analyze $getId3 = new GetId3(); $getId3->setOptionMD5Data(true)->setOptionMd5DataSource(true)->setEncoding('UTF-8'); $raw_info = $getId3->analyze($filepath); // read other important info from mp3 tags, if possible if (isset($raw_info['tags']['id3v2'])) { $song_info = array('title' => isset($raw_info['tags']['id3v2']['title']) ? $raw_info['tags']['id3v2']['title'][0] : '', 'artist' => isset($raw_info['tags']['id3v2']['artist']) ? $raw_info['tags']['id3v2']['artist'][0] : '', 'album' => isset($raw_info['tags']['id3v2']['album']) ? $raw_info['tags']['id3v2']['album'][0] : '', 'genre' => isset($raw_info['tags']['id3v2']['genre']) ? $raw_info['tags']['id3v2']['genre'][0] : '', 'length' => strlen($raw_info['playtime_string']) < 6 ? '00:' . $raw_info['playtime_string'] : $raw_info['playtime_string']); // $song_info['length'] = new \DateTime($song_info['length']); } else { // no info, and set just a null $song_info = null; } return $song_info; }