java 获取歌曲文件的信息

java 获取歌曲文件的信息,第1张

package mp3;

import javaioFile;

import javaioFileNotFoundException;

import javaioIOException;

import javaioRandomAccessFile;

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");

Systemoutprintln("文件装载完毕");

}

public static void main(String[] args) throws IOException {

ReadMp3 read = new ReadMp3();

byte[] buffer = new byte[128];

readranseek(readranlength() - 128);

readranread(buffer);

SongInfo info = new SongInfo(buffer);

Systemoutprintln("name:" + infogetSongName() + " year:"

+ infogetYear() + " 歌手:" + infogetArtist() + " 专辑名:"

+ infogetAlbum() + " 备注:" + infogetComment());

}

}

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 (datalength != 128) {

throw new RuntimeException("数据长度不合法:" + datalength);

}

String tag = new String(data, 0, 3);

// 只有前三个字节是TAG才处理后面的字节

if (tagequalsIgnoreCase("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];

Systemarraycopy(TAGgetBytes(), 0, data, 0, 3);

byte[] temp = songNamegetBytes();

Systemarraycopy(temp, 0, data, 3, templength > 30 30 : templength);

temp = artistgetBytes();

System

arraycopy(temp, 0, data, 33, templength > 30 30

: templength);

temp = albumgetBytes();

System

arraycopy(temp, 0, data, 63, templength > 30 30

: templength);

temp = yeargetBytes();

Systemarraycopy(temp, 0, data, 93, templength > 4 4 : templength);

temp = commentgetBytes();

System

arraycopy(temp, 0, data, 97, templength > 28 28

: templength);

data[125] = r1;

data[126] = r2;

data[127] = r3;

return data;

}

public String getArtist() {

return artist;

}

public void setArtist(String authorName) {

thisartist = authorName;

}

public String getComment() {

return comment;

}

public void setComment(String comment) {

thiscomment = comment;

}

public byte getR1() {

return r1;

}

public void setR1(byte r1) {

thisr1 = r1;

}

public byte getR2() {

return r2;

}

public void setR2(byte r2) {

thisr2 = r2;

}

public byte getR3() {

return r3;

}

public void setR3(byte r3) {

thisr3 = r3;

}

public String getSongName() {

return songName;

}

public void setSongName(String songName) {

if (songName == null) {

throw new NullPointerException("歌名不能是null!");

}

valid = true;

thissongName = songName;

}

public String getAlbum() {

return album;

}

public void setAlbum(String specialName) {

thisalbum = specialName;

}

public String getYear() {

return year;

}

public void setYear(String year) {

thisyear = year;

}

}

String cmd="rundll32 urldll FileProtocolHandler file://c:\爱你爱到骨头里mp3";

Process p = RuntimegetRuntime()exec(cmd);

以上就是关于java 获取歌曲文件的信息全部的内容,包括:java 获取歌曲文件的信息、java编程问题,手动设置音频文件播放时间、用Java如何得到mp3的属性等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9764447.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存