java id3v2,设置MP3 ID3v2标签中的歌词

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值