diff --git a/src/main/java/com/yutou/tools/home/nas/MusicController.java b/src/main/java/com/yutou/tools/home/nas/MusicController.java index 9d3c1c7..caef6ae 100644 --- a/src/main/java/com/yutou/tools/home/nas/MusicController.java +++ b/src/main/java/com/yutou/tools/home/nas/MusicController.java @@ -40,7 +40,7 @@ public class MusicController { } @RequestMapping("list.do") @ResponseBody - public String getMusicListOfPath(String path){ + public String getMusicListOfPath(String path,String type){ if(!StringUtils.isEmpty(path)&&!new File(path).exists()){ path=base64ToString(path); } @@ -58,7 +58,7 @@ public class MusicController { MusicTools tools = MusicTools.getInstance(); json.put("scan", tools.isScan()); json.put("size", tools.getLength()); - json.put("data", JSONArray.toJSON(tools.getPath(path))); + json.put("data", JSONArray.toJSON(tools.getPath(path,!StringUtils.isEmpty(type)))); return json.toJSONString(); } diff --git a/src/main/java/com/yutou/tools/utils/MusicTools.java b/src/main/java/com/yutou/tools/utils/MusicTools.java index e5287b9..fa55455 100644 --- a/src/main/java/com/yutou/tools/utils/MusicTools.java +++ b/src/main/java/com/yutou/tools/utils/MusicTools.java @@ -89,15 +89,23 @@ public class MusicTools { } } - public List getPath(String path) { + /** + * 获取指定目录下的音乐 + * @param path 指定目录 + * @param isDir 是否扫描目录下的所有文件,false则仅为当前目录 + * @return 音乐列表 + */ + public List getPath(String path,boolean isDir) { List 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)); + if(isDir) { + 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; } - return list; } if (musicMap.containsKey(path)) { MusicData tmp = musicMap.get(path).isEmpty() ? null : musicMap.get(path).get(0); diff --git a/web/html/body/nas/music.html b/web/html/body/nas/music.html index 767058d..fe53c63 100644 --- a/web/html/body/nas/music.html +++ b/web/html/body/nas/music.html @@ -119,7 +119,7 @@ } } else if (obj.event === 'play') { console.log(data.file) - $.get(localhost + "/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&path=" + new Base64().encode(data.file), function (obj) { + $.get(localhost + "/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&type=all&path=" + new Base64().encode(data.file), function (obj) { let json = JSON.parse(obj); console.log(json) if(json.code===0){