修复双击文件夹会显示所有音乐的问题

This commit is contained in:
Yutousama 2020-10-26 23:19:20 +08:00
parent 806b257e81
commit dbe2b3fe1c
3 changed files with 17 additions and 9 deletions

View File

@ -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();
}

View File

@ -89,8 +89,15 @@ public class MusicTools {
}
}
public List<MusicData> getPath(String path) {
/**
* 获取指定目录下的音乐
* @param path 指定目录
* @param isDir 是否扫描目录下的所有文件false则仅为当前目录
* @return 音乐列表
*/
public List<MusicData> getPath(String path,boolean isDir) {
List<MusicData> list = new ArrayList<>();
if(isDir) {
if (new File(path).isDirectory() && !path.equals(MusicController.defaultMusicPath)) {
for (String key : musicMap.keySet()) {
if (key.startsWith(path)) {
@ -99,6 +106,7 @@ public class MusicTools {
}
return list;
}
}
if (musicMap.containsKey(path)) {
MusicData tmp = musicMap.get(path).isEmpty() ? null : musicMap.get(path).get(0);
if (tmp != null) {

View File

@ -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){