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.

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

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.

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);
    }
}

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.

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.

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

I am looking for guidance on this.

有帮助吗?

解决方案

Looking at the official ID3 specification at 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)

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)

Note the extra fields in the USLT frame. You'll need a custom frame class (say, 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top