我正在我的项目中处理音频数据,我需要编写我的 mp3 文件的 ID3 标签,但是在调用 getId3 pacakge 的 WriteTags() 时出现此错误,我正在使用这个包来编写我的 id3 标签。任何人都知道如何解决它。
我在我的代码中得到这个输出;
filepath : D:/xampp/htdocs/l8/public/storage/songs/newmp3.mp3
Failed to write tags!
Tag format "id3v2" is not allowed on "" files
我的 mp3 文件保持不变。
我的控制器看起来像这样
<?php
namespace App\Http\Controllers\Artist;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
use App\Models\Track;
use GetId3\GetId3Core as GetId3;
use GetId3\Lib\Helper;
use GetId3\Write\Tags;
class TrackController extends Controller
{
function test(Request $request) {
$getID3 = new GetId3();
$TaggingFormat = 'UTF-8';
$getID3->setOption(array('encoding' => $TaggingFormat));
$tagwriter = new Tags();
$tagwriter->filename = public_path('storage/songs/newmp3.mp3');
$tagwriter->filename = str_replace('\\', '/', $tagwriter->filename);
echo "filepath : " . $tagwriter->filename."<br>";
$tagwriter->tagformats = array('id3v2');
$tagwriter->overwrite_tags = true;
$tagwriter->overwrite_tags = false;
$tagwriter->tag_encoding = $TaggingFormat;
$tagwriter->remove_other_tags = true;
// populate data array
$TagData = array(
'title' => array('My Song'),
'artist' => array('The Artist'),
'album' => array('Greatest Hits'),
'year' => array('2004'),
'genre' => array('Rock'),
'comment' => array('excellent!'),
'track' => array('04/16'),
);
$tagwriter->tag_data = $TagData;
if ($tagwriter->WriteTags()) {
echo 'Successfully wrote tags<br>';
if (!empty($tagwriter->warnings)) {
echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
}
} else {
echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
}
}
}
任何帮助表示赞赏。