php解析mp3音乐专辑信息
<code>
//解析mp3音乐文件额外信息(歌曲名/歌手/专辑名称等)
function parse_mp3($file_name) {
$info_struct = [
"song_name" => [3, 33, 'trim'],
"artist_name" => [33, 63, 'trim'],
"album_name" => [63, 93, 'trim'],
"year" => [93, 97, 'trim'],
"comment" => [97, 126, 'trim'],
"genre" => [127, 128, 'genre_name']
];
$fp = fopen($file_name, "rb") or die("文件打开失败!");
fseek($fp, -128, SEEK_END);
$mp3_info = [];
$tag = fread($fp, 3);
if ($tag == 'TAG') {
foreach ($info_struct as $key => $arr) {
fseek($fp, $arr[0] - 128, SEEK_END);
$mp3_info[$key] = call_user_func($arr[2], fread($fp, $arr[1] - $arr[0]));
}
}
fclose($fp);
return $mp3_info;
}
function genre_name($genre) {
$genre = ord($genre);
$genre_arr = [
'8' => 'Jazz',
'10' => 'New Age ',
'11' => 'Oldies ',
'12' => 'Other',
'13' => 'Pop',
'14' => 'R&B',
'15' => 'Rap',
'16' => 'Reggae',
'17' => 'Rock'
];
if (array_key_exists($genre, $genre_arr)) {
return $genre_arr[$genre];
}else{
return "Unknow";
}
}
</code>
更多>>