问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

用Java如何得到mp3的属性

发布网友 发布时间:2022-04-30 06:42

我来回答

1个回答

热心网友 时间:2023-10-19 22:30

package mp3;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class ReadMp3 {
private SongInfo info = null;
private RandomAccessFile ran = null;
private File file = null;

public ReadMp3() throws FileNotFoundException {
file = new File("./rec/感觉不到你.mp3");
ran = new RandomAccessFile(file, "r");
System.out.println("文件装载完毕");

}

public static void main(String[] args) throws IOException {
ReadMp3 read = new ReadMp3();
byte[] buffer = new byte[128];

read.ran.seek(read.ran.length() - 128);

read.ran.read(buffer);
SongInfo info = new SongInfo(buffer);
System.out.println("name:" + info.getSongName() + " year:"
+ info.getYear() + " 歌手:" + info.getArtist() + " 专辑名:"
+ info.getAlbum() + " 备注:" + info.getComment());

}
}
package mp3;

/**
* 一个歌曲信息的类的结构表示 这个歌曲是使用ID3V1的信息存储结构的
*
* @author hadeslee
*/
public class SongInfo {

private final String TAG = "TAG"; // 文件头1-3
private String songName; // 歌曲名4-33
private String artist; // 歌手名34-63
private String album; // 专辑名61-93
private String year; // 年94-97
private String comment; // 备注98-125
private byte r1, r2, r3; // 三个保留位126,127,128
private boolean valid; // 是否合法
public transient String fileName; // 此歌曲对应的文件名,没有封装

public SongInfo(byte[] data) {
if (data.length != 128) {
throw new RuntimeException("数据长度不合法:" + data.length);
}
String tag = new String(data, 0, 3);
// 只有前三个字节是TAG才处理后面的字节
if (tag.equalsIgnoreCase("TAG")) {
valid = true;
songName = new String(data, 3, 30).trim();
artist = new String(data, 33, 30).trim();
album = new String(data, 63, 30).trim();
year = new String(data, 93, 4).trim();
comment = new String(data, 97, 28).trim();
r1 = data[125];
r2 = data[126];
r3 = data[127];
} else {
valid = false;
}
}

public SongInfo() {
}

/**
* 返回是否合法
*
* @return 是否
*/
public boolean isValid() {
return valid;
}

/**
* 得到此对象的128个字节的表示形式
*
* @return
*/
public byte[] getBytes() {
byte[] data = new byte[128];
System.arraycopy(TAG.getBytes(), 0, data, 0, 3);
byte[] temp = songName.getBytes();
System.arraycopy(temp, 0, data, 3, temp.length > 30 ? 30 : temp.length);
temp = artist.getBytes();
System
.arraycopy(temp, 0, data, 33, temp.length > 30 ? 30
: temp.length);
temp = album.getBytes();
System
.arraycopy(temp, 0, data, 63, temp.length > 30 ? 30
: temp.length);
temp = year.getBytes();
System.arraycopy(temp, 0, data, 93, temp.length > 4 ? 4 : temp.length);
temp = comment.getBytes();
System
.arraycopy(temp, 0, data, 97, temp.length > 28 ? 28
: temp.length);
data[125] = r1;
data[126] = r2;
data[127] = r3;
return data;
}

public String getArtist() {
return artist;
}

public void setArtist(String authorName) {
this.artist = authorName;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public byte getR1() {
return r1;
}

public void setR1(byte r1) {
this.r1 = r1;
}

public byte getR2() {
return r2;
}

public void setR2(byte r2) {
this.r2 = r2;
}

public byte getR3() {
return r3;
}

public void setR3(byte r3) {
this.r3 = r3;
}

public String getSongName() {
return songName;
}

public void setSongName(String songName) {
if (songName == null) {
throw new NullPointerException("歌名不能是null!");
}
valid = true;
this.songName = songName;
}

public String getAlbum() {
return album;
}

public void setAlbum(String specialName) {
this.album = specialName;
}

public String getYear() {
return year;
}

public void setYear(String year) {
this.year = year;
}

}

参考资料:http://topic.csdn.net/u/20080316/19/ccd5b13c-102b-406e-8599-1368cd27c864.html?529127657

热心网友 时间:2023-10-19 22:30

package mp3;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class ReadMp3 {
private SongInfo info = null;
private RandomAccessFile ran = null;
private File file = null;

public ReadMp3() throws FileNotFoundException {
file = new File("./rec/感觉不到你.mp3");
ran = new RandomAccessFile(file, "r");
System.out.println("文件装载完毕");

}

public static void main(String[] args) throws IOException {
ReadMp3 read = new ReadMp3();
byte[] buffer = new byte[128];

read.ran.seek(read.ran.length() - 128);

read.ran.read(buffer);
SongInfo info = new SongInfo(buffer);
System.out.println("name:" + info.getSongName() + " year:"
+ info.getYear() + " 歌手:" + info.getArtist() + " 专辑名:"
+ info.getAlbum() + " 备注:" + info.getComment());

}
}
package mp3;

/**
* 一个歌曲信息的类的结构表示 这个歌曲是使用ID3V1的信息存储结构的
*
* @author hadeslee
*/
public class SongInfo {

private final String TAG = "TAG"; // 文件头1-3
private String songName; // 歌曲名4-33
private String artist; // 歌手名34-63
private String album; // 专辑名61-93
private String year; // 年94-97
private String comment; // 备注98-125
private byte r1, r2, r3; // 三个保留位126,127,128
private boolean valid; // 是否合法
public transient String fileName; // 此歌曲对应的文件名,没有封装

public SongInfo(byte[] data) {
if (data.length != 128) {
throw new RuntimeException("数据长度不合法:" + data.length);
}
String tag = new String(data, 0, 3);
// 只有前三个字节是TAG才处理后面的字节
if (tag.equalsIgnoreCase("TAG")) {
valid = true;
songName = new String(data, 3, 30).trim();
artist = new String(data, 33, 30).trim();
album = new String(data, 63, 30).trim();
year = new String(data, 93, 4).trim();
comment = new String(data, 97, 28).trim();
r1 = data[125];
r2 = data[126];
r3 = data[127];
} else {
valid = false;
}
}

public SongInfo() {
}

/**
* 返回是否合法
*
* @return 是否
*/
public boolean isValid() {
return valid;
}

/**
* 得到此对象的128个字节的表示形式
*
* @return
*/
public byte[] getBytes() {
byte[] data = new byte[128];
System.arraycopy(TAG.getBytes(), 0, data, 0, 3);
byte[] temp = songName.getBytes();
System.arraycopy(temp, 0, data, 3, temp.length > 30 ? 30 : temp.length);
temp = artist.getBytes();
System
.arraycopy(temp, 0, data, 33, temp.length > 30 ? 30
: temp.length);
temp = album.getBytes();
System
.arraycopy(temp, 0, data, 63, temp.length > 30 ? 30
: temp.length);
temp = year.getBytes();
System.arraycopy(temp, 0, data, 93, temp.length > 4 ? 4 : temp.length);
temp = comment.getBytes();
System
.arraycopy(temp, 0, data, 97, temp.length > 28 ? 28
: temp.length);
data[125] = r1;
data[126] = r2;
data[127] = r3;
return data;
}

public String getArtist() {
return artist;
}

public void setArtist(String authorName) {
this.artist = authorName;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public byte getR1() {
return r1;
}

public void setR1(byte r1) {
this.r1 = r1;
}

public byte getR2() {
return r2;
}

public void setR2(byte r2) {
this.r2 = r2;
}

public byte getR3() {
return r3;
}

public void setR3(byte r3) {
this.r3 = r3;
}

public String getSongName() {
return songName;
}

public void setSongName(String songName) {
if (songName == null) {
throw new NullPointerException("歌名不能是null!");
}
valid = true;
this.songName = songName;
}

public String getAlbum() {
return album;
}

public void setAlbum(String specialName) {
this.album = specialName;
}

public String getYear() {
return year;
}

public void setYear(String year) {
this.year = year;
}

}

参考资料:http://topic.csdn.net/u/20080316/19/ccd5b13c-102b-406e-8599-1368cd27c864.html?529127657

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
办公软件综合实训图书信息 什么是高分子材料与工程高分子材料与工程介绍 抖音超市普通人怎么入驻 抖音上的超市怎么入驻的 胃胀,有时还有点痛:还嗝气请问吃什么药, ...喝水也吐经常嗝气吃东西就胃胀气经常胃酸有时候胃特别热烧心的感觉... 它是指示代词还是人称代词 指示代词和人称代词语文 汉语指示代词和人称代词区别 长款的牛仔衣如何搭配最出彩? 北方稀土一年走势?北方稀土全年股票走势图?北方稀土股多少价位可以建仓? 请问大庆火车站咨询电话是多少? 谁有java教程,百度云下载,要从基础到精通。还要vs2008中文版下载 今日北方稀土走势分析 跪求大庆市萨尔图火车站咨询电话!! java教程视频下载 宁波韵升以后走势如何?宁波韵升一个月走势图?宁波韵升股发行价多少? 谁知道大庆萨尔图火车站电话号码,急用! 北方稀土股票后期走势预测图 怎么用Java写一个简单的mp3播放器,用外部包 大庆火车站电话是什么 急求java教学视频的下载地址! 必加分谢! 北方稀土新手走势?北方稀土股票走势图线?北方稀土发行价和开盘价? 大庆西站火车站问事处电话是多少? 北方稀土下午走势?北方稀土股票未来走势图?北方稀土发行价多少钱? java 打开mp3文件 北方稀土的走势图如何? java编写 mp3播放器 代码 北方稀土下礼拜走势?北方稀土股票历史走势图?北方稀土发行股价多少? JAVA做音乐播放器简单吗 金力永磁股前景怎样?金力永磁是上市时价格?金力永磁的今日走势分析? 跪求毕向东25天javajava视频教程,在网上找到的解压之后都是音频,想要视频,谁有呢 大庆火车站办理宠物犬托运手续? Java语法视频教程免费下载 java写mp3播放器 【为什么大庆火车站的问事处电话打不通呢】 大庆火车站预订火车票电话号码是什么Y(^_^)Y 谁知道大庆火车站 应该提前几天买票 包头青山24小时药店地址? 包头24小时药店开门营业了东河 包头哪药店最大? 吃什么可以健脾养肾? 夏天补肾吃什么好 9个食谱健脾补肾 微信上的聊天记录可以迁移到新手机吗 不同怎么迁移聊天记录? 女人吃什么健脾补肾一 400个聊天记录迁移要多久 聊天记录可以转到另一个上吗? 中国中车股票适合长期持有吗 中国中车股票怎么样?