0

我使用了 getid3_write_lyrics3库。不工作

这是我的代码:

// Enter your filename here 
$filename = 'C:\xampp\htdocs\source2\test.mp3';

//Include getID3() library (can be in a different 
                         directory if full path is specified)
require_once('getid3.php');

// Include desired writer module
require_once('write.lyrics3.php');

//Instantiate desired tag class
$tw = new getid3_write_lyrics3($filename);



// Attempt to write new tag  -- NOTE: all values must be in ISO-8859-1
try 
{
    $tw->title      = 'bhavi';
    $tw->artist     = 'asas';
    $tw->album      = 'A new album';
    $tw->author     = 'bhavi author';
    $tw->comment    = 'bhavika commment';
    $tw->images     = 'C:\xampp\htdocs\source2\image.jpg';

    $tw->synched    = true;
    $tw->lyrics     = "[00:02]Let's talk about time\r\n[00:02]tickin' away 
      every day\r\n[00:05]so wake on up before it's gone away\r\n";

    if(!$tw->write())
    {
        echo "not success";
    }else{
        print 'New tag written<br>';
    }
 }catch (Exception $e) 
 {
   print $e->message;
 }

输出

新标签写入

但 MP# 文件显示空白 MP3 标签。显示我下面的屏幕截图。

截屏:

在此处输入图像描述

4

2 回答 2

1

由于 OP 并没有真正提出问题,并在评论中提到他想用 id3 将歌词添加到 mp3,所以我正在回答。你不必使用歌词3,你可以使用普通的id3v2。

我在使用 getID3 包保存歌词时遇到了类似的问题。这是因为文件“getID3/getid3/write.id3v2.php”第 1982 行和第 2057 行中的 getID3 存在语法问题。

我会简单地评论@Tom的答案,但我还不能评论。所以我正在使用他的代码:

$filename = 'fullpath/to/your/music.mp3' ;
$sLyrics = "the lyrics go here" ;

$TextEncoding = 'UTF-8';
require_once('./getid3/getid3/getid3.php'); 

$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));

require_once('./getid3/getid3/write.php');

$tagwriter = new getid3_writetags;
$tagwriter->filename = $filename ;
$tagwriter->tagformats = array('id3v2.3');
$tagwriter->overwrite_tags    = true;  
$tagwriter->remove_other_tags = false; 
$tagwriter->tag_encoding      = $TextEncoding;

$TagData = array(
    'unsychronised_lyric' => array( $sLyrics ),
);
$tagwriter->tag_data = $TagData;

$tagwriter->WriteTags();

关键是将 'unsynchronised_lyrics' 更改为 'unsychronised_lyric' 并出现拼写错误。我在JamesHeinrich getId3中为此打开了一个问题,所以当你更新包时要小心,如果他们将来将它改回正常,这样你的代码就不会停止写歌词。

更新 - -

当我立即收到答复时,拼写错误不是来自 getID3 包,而是直接来自id3 Org,因此它将保持原样。所以安全地使用'unsychronised_lyric'。

于 2017-12-06T16:29:31.270 回答
0

是的,我认为这是您正在使用的演示代码。对我也不起作用,即使运行它会返回 true。如果它没有正确返回错误,则很难寻找错误。

使用相同的库,这完成了工作:

$filename = 'fullpath/to/your/music.mp3' ;
$sLyrics = "the lyrics go here" ;

$TextEncoding = 'UTF-8';
require_once('./getid3/getid3/getid3.php'); 

$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));

require_once('./getid3/getid3/write.php');

$tagwriter = new getid3_writetags;
$tagwriter->filename = $filename ;
$tagwriter->tagformats = array('id3v2.3');
$tagwriter->overwrite_tags    = true;  
$tagwriter->remove_other_tags = false; 
$tagwriter->tag_encoding      = $TextEncoding;

$TagData = array(
    'unsynchronised_lyrics' => array( $sLyrics ),
);
$tagwriter->tag_data = $TagData;

$tagwriter->WriteTags();
于 2017-05-05T10:52:10.217 回答