很多时候,我们有必要的到一些歌曲的信息,比如歌手的专辑,歌手名 歌曲名,下面就是java写的获取MP3歌曲信息
首先加入 jid3lib-0.5.4.jar包
import java.io.IOException;
import org.farng.mp3.MP3File;
import org.farng.mp3.TagException;
import org.farng.mp3.id3.AbstractID3v2;
import org.farng.mp3.id3.ID3v1;
import org.farng.mp3.lyrics3.AbstractLyrics3;
public class GetparmsMp3 {
public static void main(String[] args) {
try {
MP3File file = new MP3File("D:\\upload\\Kalimba.mp3");//1,lyrics
AbstractID3v2 id3v2 = file.getID3v2Tag();
ID3v1 id3v1 = file.getID3v1Tag();
if (id3v2 != null) {
System.out.println("id3v2");
// if("".equals(id3v2.getAlbumTitle())) {
// String s= id3v2.getSongTitle();
// String b ="a";
// }
System.out.println(id3v2.getAlbumTitle());//专辑名
String a= id3v2.getSongTitle();
System.out.println(a+"111");
System.out.println(id3v2.getSongTitle());//歌曲名
System.out.println(id3v2.getLeadArtist());//歌手
} else {
System.out.println("id3v1");
System.out.println(id3v1.getAlbumTitle());
System.out.println(id3v1.getSongTitle());
System.out.println(id3v1.getLeadArtist());
}
AbstractLyrics3 lrc3Tag = file.getLyrics3Tag();
if (lrc3Tag != null) {
String lyrics = lrc3Tag.getSongLyric();
System.out.println(lyrics);
}
} catch (IOException e) {
e.printStackTrace();
} catch (TagException e) {
e.printStackTrace();
}
System.out.println("over");
}
}