I am working on audio data in my project and I need to write ID3 tags of my mp3 files, but I am getting this error when calling WriteTags() of getId3 pacakge, I am using this package to write my id3 tags. any one has any idea about how to fix it.
I am getting this output in my code;
filepath : D:/xampp/htdocs/l8/public/storage/songs/newmp3.mp3
Failed to write tags!
Tag format "id3v2" is not allowed on "" files
and my mp3 file remains unmodified.
My controller looks like this
<?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);
}
}
}
Any help is appreciated.