扩展音乐参数
This commit is contained in:
parent
cb0ccd24d2
commit
fa61b83665
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>com.yutou</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.0.10.3</version>
|
||||
<version>1.0.10.4</version>
|
||||
<name>tools</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
public class ToolsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("当前版本号:1.0.10.3");
|
||||
System.out.println("当前版本号:1.0.10.4");
|
||||
SpringApplication.run(ToolsApplication.class, args);
|
||||
RedisTools.initRedisPoolSub();
|
||||
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) {
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.util.StringUtils;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
|
||||
@Data
|
||||
public class MusicData {
|
||||
@ -27,6 +28,17 @@ public class MusicData {
|
||||
private String lastDir;//上一个文件夹
|
||||
private boolean isDir = false;
|
||||
|
||||
private int bitRate;//比特率
|
||||
private int sampleRate;//采样率
|
||||
private long noOfSamples;//采样数
|
||||
private int channelCount;//声道
|
||||
private String encodingType;//解码类型
|
||||
private double durationAsDouble;//持续时长
|
||||
private boolean lossless;//无损
|
||||
private boolean variableBitRate;//固定码率
|
||||
private String md5;//确保是同一个文件
|
||||
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
this.isDir = file.isDirectory();
|
||||
@ -66,5 +78,4 @@ public class MusicData {
|
||||
|
||||
return Files.readAllBytes(Paths.get(img.getAbsolutePath()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package com.yutou.tools.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.home.nas.Data.MusicData;
|
||||
import com.yutou.tools.home.nas.MusicController;
|
||||
import ealvatag.audio.AudioFile;
|
||||
import ealvatag.audio.AudioFileIO;
|
||||
import ealvatag.audio.AudioHeader;
|
||||
import ealvatag.audio.exceptions.CannotReadException;
|
||||
import ealvatag.tag.FieldKey;
|
||||
import ealvatag.tag.NullTag;
|
||||
import ealvatag.tag.Tag;
|
||||
import ealvatag.tag.flac.FlacTag;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
@ -36,13 +39,13 @@ public class MusicTools {
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
String time=new SimpleDateFormat("HH:mm").format(new Date());
|
||||
if(time.equals("00:00")){
|
||||
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
||||
if (time.equals("00:00")) {
|
||||
System.out.println("零点刷新列表");
|
||||
scanMusic();
|
||||
}
|
||||
}
|
||||
},0,10*1000);
|
||||
}, 0, 10 * 1000);
|
||||
}
|
||||
|
||||
public synchronized void scanMusic() {
|
||||
@ -103,13 +106,14 @@ public class MusicTools {
|
||||
|
||||
/**
|
||||
* 获取指定目录下的音乐
|
||||
* @param path 指定目录
|
||||
*
|
||||
* @param path 指定目录
|
||||
* @param isDir 是否扫描目录下的所有文件,false则仅为当前目录
|
||||
* @return 音乐列表
|
||||
*/
|
||||
public List<MusicData> getPath(String path,boolean isDir) {
|
||||
public List<MusicData> getPath(String path, boolean isDir) {
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
if(isDir) {
|
||||
if (isDir) {
|
||||
if (new File(path).isDirectory() && !path.equals(MusicController.defaultMusicPath)) {
|
||||
for (String key : musicMap.keySet()) {
|
||||
if (key.startsWith(path)) {
|
||||
@ -232,6 +236,21 @@ public class MusicTools {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
data.setFile(file);
|
||||
|
||||
AudioHeader header = audioFile.getAudioHeader();
|
||||
data.setBitRate(header.getBitRate());
|
||||
data.setSampleRate(header.getSampleRate());
|
||||
data.setNoOfSamples(header.getNoOfSamples());
|
||||
data.setChannelCount(header.getChannelCount());
|
||||
data.setEncodingType(header.getEncodingType());
|
||||
data.setDurationAsDouble(header.getDurationAsDouble());
|
||||
data.setLossless(header.isLossless());
|
||||
data.setVariableBitRate(header.isVariableBitRate());
|
||||
try {
|
||||
data.setMd5(header.getClass().getMethod("getMd5").invoke(header).toString());
|
||||
} catch (Exception ignored) {
|
||||
data.setMd5(Base64.getEncoder().encodeToString(file.getAbsolutePath().getBytes()));
|
||||
}
|
||||
return data;
|
||||
} catch (CannotReadException e) {
|
||||
MusicData data = new MusicData();
|
||||
@ -302,9 +321,9 @@ public class MusicTools {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String base = "bXVzaWMuaHRtbDo2MyBaOlzpn7PkuZBc55m75bGx5bCR5aWzXFtzM11bRURd6Imy6YGV44GE44Gu57%2B8XDAyLiAwMiDoibLpgZXjgYTjga7nv7wgKOOBguOBiuOBhOODkOODvOOCuOODp%2BODsykud2F2Cg%3D%3D";
|
||||
byte[] bytes = getInstance().getMetadata(new File("Z:\\音乐\\BanG Dream!\\Poppin'on!\\B.O.F.flac")).readImage();
|
||||
System.out.println(bytes.length);
|
||||
AudioFile audioFile = AudioFileIO.read(new File("C:\\Users\\admin\\Music\\34\\周杰伦 - 说好不哭(with 五月天阿信).flac"));
|
||||
AudioHeader header = audioFile.getAudioHeader();
|
||||
System.out.println(JSONObject.toJSONString(header));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user