From dbe2b3fe1ca54414896663dfbbb448634aeddc70 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 26 Oct 2020 23:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=8C=E5=87=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E4=BC=9A=E6=98=BE=E7=A4=BA=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=9F=B3=E4=B9=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yutou/tools/home/nas/MusicController.java | 4 ++-- .../com/yutou/tools/utils/MusicTools.java | 20 +++++++++++++------ web/html/body/nas/music.html | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) 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){