Java获取音乐文件艺术家,歌曲名,所属专辑等信息

/**
* 获取MP3文件信息
*
* @param musicFile
* MP3文件对象
*/
private void getMusicInfo(File musicFile) {
try {
RandomAccessFile randomAccessFile = new RandomAccessFile(musicFile,"r");
byte[] buffer = new byte[128];
randomAccessFile.seek(randomAccessFile.length() - 128);
randomAccessFile.read(buffer);
if (buffer.length == 128) {
String tag = new String(buffer, 0, 3);
// 只有前三个字节是TAG才处理后面的字节
if (tag.equalsIgnoreCase("TAG")) {
// 歌曲名
String songName = new String(buffer, 3, 30).trim();
// 艺术家
String artist = new String(buffer, 33, 30).trim();
// 所属唱片
String album = new String(buffer, 63, 30).trim();
// 发行年
String year = new String(buffer, 93, 4).trim();
// 备注
String comment = new String(buffer, 97, 28).trim();
System.out.println(songName + "\t" + artist + "\t" + album
+ "\t" + year + "\t" + comment);
} else {
System.out.println("无效的歌曲信息...");
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}


原文地址:http://hi.baidu.com/timesten/item/25c68e10e0e7b63eb9318013

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值