设置MP3 ID3v2标签中的歌词 [英] Set Lyrics in MP3 ID3v2 Tag

查看:423
本文介绍了设置MP3 ID3v2标签中的歌词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android应用程序中为一个mp3写歌词。我找到了一个java库,用于读取 mp3 文件和读取/操作ID3标签(ID3v1和ID3v2) .2到ID3v2.4),名为 mp3agic

I want to write lyrics to an mp3 in an Android application.I have found a java library for reading mp3 files and reading/manipulating the ID3 tags (ID3v1 and ID3v2.2 through ID3v2.4), named mp3agic.

我修改了 mp3agic 来编写ID3v2标签的歌词标签,写下标签: USLT 。可在维基百科中找到

I modified mp3agic to write the lyric tag of the ID3v2 tag, writing the tag: USLT. Found in Wikipedia

在Android应用示例中,我修改了MP3的艺术家,专辑,标题,流派,歌词和评论。除了歌词之外,所有标签都被正确修改。 PowerAMP 用于验证修改后的 MP3 文件和 PowerAMP 在MP3中找不到歌词。

In a sample Android app I modify the artist, album, title, genre, lyrics, and comment of an MP3. All tags are modified correct except for the lyrics. PowerAMP is used to verify the modified MP3 file and PowerAMP cannot find the lyrics in the MP3.

如果有人熟悉这个库,这里是我修改后的代码来自AbstractID3v2Tag.java:

If anyone is familiar with this library here is my modified code from AbstractID3v2Tag.java:

//define lyric tag for id3v2
public static final String ID_TEXT_LYRICS = "USLT";

//get the lyrics from the tag
public String getLyrics() {
    ID3v2TextFrameData frameData;
    if (obseleteFormat) return null;
    else frameData = extractTextFrameData(ID_TEXT_LYRICS);
    if (frameData != null && frameData.getText() != null) 
        return frameData.getText().toString();
    return null;
}

//set the lyrics in the tag
public void setLyrics(String lyrics) {
    if (lyrics != null && lyrics.length() > 0) {
        invalidateDataLength();
        ID3v2TextFrameData frameData = new ID3v2TextFrameData(useFrameUnsynchronisation(), new EncodedText(lyrics));
        addFrame(createFrame(ID_TEXT_LYRICS, frameData.toBytes()), true);
    }
}

我将歌词设置为 MP3 在Windows中使用程序并使用我的应用程序读取 USLT 标记并使用 getLyrics()返回字符串 eng PowerAMP 确实找到了Windows程序设置的这些歌词。

I set the lyrics on an MP3 with a program in Windows and read the USLT tag with my app and getLyrics() returned the string eng. PowerAMP did find these lyrics set by the Windows program.

我搜索过并找到许多指向MP3 ID3标签修改器库的帖子,这就是我发现mp3agic的地方。这是我可以轻松修改的唯一一个包含更改歌词的库。

I have searched and found many posts pointing to MP3 ID3 tag modifier library's, that's where I found mp3agic. Which is the only library I could easily modify to incorporate changing of lyrics.

我找到的一个库是 MyID3_for_Android ,没有修改歌词的方法。

One library I found was MyID3_for_Android which did not have a method to modify lyrics.

我在寻找对此的指导。

推荐答案

查看 http://id3.org/id3v2.4.0-frames

Header for 'Unsynchronised lyrics/text transcription', ID: "USLT":
    Text encoding        $xx
    Language             $xx xx xx
    Content descriptor   (text string according to encoding) $00 (00)
    Lyrics/text          (full text string according to encoding)

因此,USLT框架不仅仅是一个文本框架,这是你试图解析它的方式。相比之下,文本框架如下所示:

So, the USLT frame is not just a text frame, which is how you're trying to parse it. By comparison, a text frame looks like this:

Header for 'Text information frame', ID: "T000" - "TZZZ" excluding "TXXX":
    Text encoding                $xx
    Information                  (text string(s) according to encoding)

注意USLT框架中的额外字段。你需要一个自定义的框架类(比如,ID3v2LyricsFrameData)。

Note the extra fields in the USLT frame. You'll need a custom frame class (say, ID3v2LyricsFrameData).

然而,USLT框架与评论框架(COMM)非常相似,所以你可能会重新使用一些代码。也许创建一个ID3v2CommentFrameData和ID3v2LyricsFrameData都扩展的超类。

The USLT frame is however very similar to a comment frame (COMM), so you can probably re-use some of this code. Perhaps create a superclass that ID3v2CommentFrameData and ID3v2LyricsFrameData both extend.

这篇关于设置MP3 ID3v2标签中的歌词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆