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 caef6ae..3683fb5 100644 --- a/src/main/java/com/yutou/tools/home/nas/MusicController.java +++ b/src/main/java/com/yutou/tools/home/nas/MusicController.java @@ -62,12 +62,21 @@ public class MusicController { return json.toJSONString(); } + @RequestMapping("reload.do") + @ResponseBody + public String reload(){ + JSONObject json=new JSONObject(); + MusicTools.getInstance().scanMusic(); + json.put("msg","ok"); + json.put("code",0); + return json.toJSONString(); + } @RequestMapping("find/file.do") @ResponseBody public String findFile(String path){ JSONObject json=new JSONObject(); if(StringUtils.isEmpty(path)){ - json.put("code",0); + json.put("code",-1); json.put("msg","地址为空"); 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 fa55455..c540886 100644 --- a/src/main/java/com/yutou/tools/utils/MusicTools.java +++ b/src/main/java/com/yutou/tools/utils/MusicTools.java @@ -11,6 +11,7 @@ import ealvatag.tag.Tag; import org.springframework.util.StringUtils; import java.io.*; +import java.text.SimpleDateFormat; import java.util.*; public class MusicTools { @@ -32,6 +33,16 @@ public class MusicTools { private MusicTools() { scanMusic(); + new Timer().schedule(new TimerTask() { + @Override + public void run() { + String time=new SimpleDateFormat("HH:mm").format(new Date()); + if(time.equals("00:00")){ + System.out.println("零点刷新列表"); + scanMusic(); + } + } + },0,10*1000); } public synchronized void scanMusic() { @@ -170,6 +181,8 @@ public class MusicTools { if (file.getName().endsWith(".lrc") || file.getName().endsWith(".jpg") || file.getName().endsWith(".ini") + || file.getName().endsWith(".png") + || file.getName().endsWith(".torrent") ) { return null; } diff --git a/web/html/body/nas/music.html b/web/html/body/nas/music.html index fe53c63..f08bfa8 100644 --- a/web/html/body/nas/music.html +++ b/web/html/body/nas/music.html @@ -32,6 +32,7 @@
+ 刷新曲库 @@ -168,10 +169,13 @@ }); $('#download').click(function () { window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + playNow) - }) + }); $('#next').click(function (){ playNext() - }) + }); + $('#reload').click(function (){ + $.get(localhost+"/nas/music/reload.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk") + }); function playNext() {