新增播放整个文件夹功能
新增下一首功能
This commit is contained in:
@@ -41,9 +41,16 @@ public class MusicController {
|
||||
@RequestMapping("list.do")
|
||||
@ResponseBody
|
||||
public String getMusicListOfPath(String path){
|
||||
if(StringUtils.isEmpty(path)||path.equals("root")){
|
||||
if(!StringUtils.isEmpty(path)&&!new File(path).exists()){
|
||||
path=base64ToString(path);
|
||||
}
|
||||
if(StringUtils.isEmpty(path)
|
||||
||path.equals("root")
|
||||
||!path.contains(defaultMusicPath)
|
||||
){
|
||||
path=defaultMusicPath;
|
||||
}
|
||||
|
||||
//path=path.replace(defaultMusicPath+File.separator,"");
|
||||
JSONObject json=new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
@@ -20,7 +20,7 @@ public class MusicTools {
|
||||
private static MusicTools tools;
|
||||
private String musicPath = "C:\\Users\\admin\\Music";
|
||||
private final List<MusicData> musicList = new ArrayList<>();
|
||||
private HashMap<String,List<MusicData>> musicMap=new HashMap<String,List<MusicData>>();
|
||||
private HashMap<String, List<MusicData>> musicMap = new HashMap<String, List<MusicData>>();
|
||||
private boolean isScan = false;
|
||||
|
||||
public static MusicTools getInstance() {
|
||||
@@ -29,12 +29,13 @@ public class MusicTools {
|
||||
}
|
||||
return tools;
|
||||
}
|
||||
private MusicTools(){
|
||||
|
||||
private MusicTools() {
|
||||
scanMusic();
|
||||
}
|
||||
|
||||
public synchronized void scanMusic() {
|
||||
if(isScan){
|
||||
if (isScan) {
|
||||
return;
|
||||
}
|
||||
System.out.println("执行扫描");
|
||||
@@ -76,12 +77,32 @@ public class MusicTools {
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<MusicData> getPath(String path){
|
||||
if(musicMap.containsKey(path)){
|
||||
List<MusicData> list=new ArrayList<>();
|
||||
MusicData tmp=musicMap.get(path).isEmpty()?null:musicMap.get(path).get(0);
|
||||
if(tmp!=null){
|
||||
if(!tmp.getFile().getParent().equals(MusicController.defaultMusicPath)) {
|
||||
|
||||
public void getPathOrDir(String path, List<MusicData> list) {
|
||||
File files = new File(path);
|
||||
for (File file : files.listFiles()) {
|
||||
if (file.isFile()) {
|
||||
list.add(getMetadata(file));
|
||||
} else {
|
||||
getPathOrDir(file.getAbsolutePath(), list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<MusicData> getPath(String path) {
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
if (new File(path).isDirectory()&&!path.equals(MusicController.defaultMusicPath)) {
|
||||
for (String key : musicMap.keySet()) {
|
||||
if(key.startsWith(path)){
|
||||
list.addAll(musicMap.get(key));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
if (musicMap.containsKey(path)) {
|
||||
MusicData tmp = musicMap.get(path).isEmpty() ? null : musicMap.get(path).get(0);
|
||||
if (tmp != null) {
|
||||
if (!tmp.getFile().getParent().equals(MusicController.defaultMusicPath)) {
|
||||
MusicData t2 = new MusicData();
|
||||
t2.setTitle("返回");
|
||||
t2.setFile(new File(tmp.getLastDir()));
|
||||
@@ -92,13 +113,14 @@ public class MusicTools {
|
||||
getDirList(path, list);
|
||||
list.addAll(musicMap.get(path));
|
||||
return list;
|
||||
}else{
|
||||
if(path.contains(MusicController.defaultMusicPath)){
|
||||
List<MusicData> list=new ArrayList<>();
|
||||
} else {
|
||||
if (path.contains(MusicController.defaultMusicPath)) {
|
||||
MusicData t2 = new MusicData();
|
||||
t2.setTitle("返回");
|
||||
t2.setFile(new File(path).getParentFile());
|
||||
list.add(t2);
|
||||
if (!path.equals(MusicController.defaultMusicPath)) {
|
||||
list.add(t2);
|
||||
}
|
||||
getDirList(path, list);
|
||||
return list;
|
||||
}
|
||||
@@ -108,10 +130,10 @@ public class MusicTools {
|
||||
}
|
||||
|
||||
private void getDirList(String path, List<MusicData> list) {
|
||||
File file=new File(path);
|
||||
File file = new File(path);
|
||||
for (File listFile : file.listFiles()) {
|
||||
if(listFile.isDirectory()){
|
||||
MusicData data=new MusicData();
|
||||
if (listFile.isDirectory()) {
|
||||
MusicData data = new MusicData();
|
||||
data.setTitle(listFile.getName());
|
||||
data.setFile(listFile);
|
||||
list.add(data);
|
||||
@@ -123,15 +145,15 @@ public class MusicTools {
|
||||
MusicData data = getMetadata(file);
|
||||
if (data != null) {
|
||||
musicList.add(data);
|
||||
String path=file.getAbsolutePath().replace(File.separator+file.getName(),"");
|
||||
String path = file.getAbsolutePath().replace(File.separator + file.getName(), "");
|
||||
List<MusicData> list;
|
||||
if(musicMap.containsKey(path)){
|
||||
list=musicMap.get(path);
|
||||
}else{
|
||||
list=new ArrayList<>();
|
||||
if (musicMap.containsKey(path)) {
|
||||
list = musicMap.get(path);
|
||||
} else {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
list.add(data);
|
||||
musicMap.put(path,list);
|
||||
musicMap.put(path, list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,9 +279,9 @@ public class MusicTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
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();
|
||||
byte[] bytes = getInstance().getMetadata(new File("Z:\\音乐\\BanG Dream!\\Poppin'on!\\B.O.F.flac")).readImage();
|
||||
System.out.println(bytes.length);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user