我尝试编写一个 php 脚本来获取封面图像并将其用作使用 getid3 php 的 mp3 文件的封面图像,但封面图像未显示在媒体播放器中。
封面图片显示在 Windows 文件夹中,但未显示在媒体播放器图标徽章中...也未显示在 google play music on android 中。
下面是代码。
<?php
$scr1=$_POST['search1'];
$op90=$_POST['search2'];
$kat=$_POST['search3'];
$album=$_POST['search4'];
$genre=$_POST['search5'];
$TextEncoding = 'UTF-8';
$albumPath = "../../image/".$scr1.".jpg"; // path to your image
require_once("../getid3/getid3.php");
// Initialize getID3 engine
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));
require_once("../getid3/write.php");
// Initialize getID3 tag-writing module
$tagwriter = new getid3_writetags;
$tagwriter->filename = '../../../public_html/song/'.$op90.'.mp3';
$filename='../../../public_html/song/'.$op90.'.mp3';
//$tagwriter->tagformats = array('id3v1', 'id3v2.3');
$tagwriter->tagformats = array('id3v2.3');
$ThisFileInfo = $getID3->analyze($filename);
// set various options (optional)
$tagwriter->overwrite_tags = true; // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental)
$tagwriter->remove_other_tags = false; // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is.
$tagwriter->tag_encoding = $TextEncoding;
$tagwriter->remove_other_tags = true;
// populate data array
$TagData = array(
'title' => array($op90),
'artist' => array($kat),
'album' => array($album),
'year' => array($ThisFileInfo['comments_html']['year'][0]),
'genre' => array($genre),
'comment' => array($ThisFileInfo['comments_html']['comment'][0]),
'track' => array($ThisFileInfo['comments_html']['track'][0]),
);
$fd = fopen($albumPath, 'rb');
$APICdata = fread($fd, filesize($albumPath));
fclose($fd);
if($APICdata) {
$TagData += array(
'attached_picture' => array(0 => array(
'data' => $APICdata,
'picturetypeid' => '0x03',
'description' => 'cover',
'mime' => image_type_to_mime_type(@$albumExifType)
))
);
}
$tagwriter->tag_data = $TagData;
// write tags
if ($tagwriter->WriteTags()) {if (!empty($tagwriter->warnings)) {}} else {}