2012-04-13 2 views
1

이 코드를 사용하여 MP3 파일의 ID3 정보를 가져옵니다.MP3에서 앨범 아트 가져 오기 PHP

<?php 
    class CMP3File { 
    var $title;var $artist;var $album;var $year;var $comment;var $genre; 
    function getid3 ($file) { 
     if (file_exists($file)) { 
     $id_start=filesize($file)-128; 
     $fp=fopen($file,"r"); 
     fseek($fp,$id_start); 
     $tag=fread($fp,3); 
     if ($tag == "TAG") { 
     $this->title=fread($fp,30); 
     $this->artist=fread($fp,30); 
     $this->album=fread($fp,30); 
     $this->year=fread($fp,4); 
     $this->comment=fread($fp,30); 
     $this->genre=fread($fp,1); 
     fclose($fp); 
     return true; 
     } else { 
     fclose($fp); 
     return false; 
     } 
     } else { return false; } 
    } 
    } 
    ?> 

다음 코드를 사용하여이 코드를 호출합니다.

 include ("CMP3File.php"); 
    $filename="music_file.mp3"; 
    $mp3file=new CMP3File; 
    $mp3file->getid3($filename); 
    echo "Title: $mp3file->title<br>\n"; 
    echo "Artist: $mp3file->artist<br>\n"; 
    echo "Album: $mp3file->album<br>\n"; 
    echo "Year: $mp3file->year<br>\n"; 
    echo "Comment: $mp3file->comment<br>\n"; 
    echo "Genre: " . Ord($mp3file->genre) . "<br>\n"; 

앨범 아트를 이미지로 가져 와서 반향시킬 수있는 방법이 있습니까?

+0

그는 자신이 시도한 코드를 게시하고 표지 이미지를 포함시키는 방법을 알고 싶어합니다. 그게 너무 지역화 된거야? – DanMan

답변

3

포함 된 이미지를 지원하지 않는 파일에서 ID3v1 태그를 읽는 중입니다. ID3v2 태그에서 앨범 아트를 읽으려면 KTagLib과 같은 기존 라이브러리를 사용하는 것이 좋습니다.

또는 ID3v2 spec을 검토하여 직접 구현할 수도 있습니다.