日期:2014-05-20  浏览次数:20635 次

我有一段程序如下,可以提取mp3文件的信息,但是到comment以后,就没有了. 我需要提取"Genre"信息,好像是tag只有128个字节.请高手帮忙
int TAG_SIZE = 128;
  int TITLE_SIZE = 30;
  int ARTIST_SIZE = 30;
  int ALBUM_SIZE = 30;
  int YEAR_SIZE = 4;
  int COMMENT_SIZE = 29;
  int TRACK_LOCATION = 126;
  int GENRE_LOCATION = 127;
  int MAX_GENRE = 255;
  int MAX_TRACK = 255;
  String ENC_TYPE = "Cp437";
  String TAG_START = "TAG";
try {
  File mp3 = new File(item.getName());
  RandomAccessFile raf = new RandomAccessFile(mp3, "r");
  raf.seek(raf.length() - TAG_SIZE );
  byte[] buf = new byte[TAG_SIZE];
  raf.read(buf, 0, TAG_SIZE);
  String tag = new String(buf, 0, TAG_SIZE, "Cp437");
  int start = TAG_START.length();
  out.println("TITLE:" + tag.substring(start, start += TITLE_SIZE).trim());
  out.println("ARTIST:" + tag.substring(start, start += ARTIST_SIZE).trim());
  out.println("ALBUM:" + tag.substring(start, start += ALBUM_SIZE).trim());
  out.println("YEAR:" + tag.substring(start, start += YEAR_SIZE).trim());
  out.println("COMMENT:" + tag.substring(start, start += COMMENT_SIZE).trim());
  out.println("TRACK:" + tag.substring(start, start += TRACK_LOCATION).trim());
  out.println("GENRE:" + tag.substring(start, start += GENRE_LOCATION).trim());
  out.println("MAX_GENRE:" + tag.substring(start, start += MAX_GENRE).trim());
  out.println("MAX_TRACK:" + tag.substring(start, start += MAX_TRACK).trim());
  }catch (Exception e) {
}


------解决方案--------------------
genre信息在ID3v1里面只有一个字节,它用不同的值代表不同的流派