From cfb36dd830474a4b5506d7e6f37b76e125258c1c Mon Sep 17 00:00:00 2001 From: yutou Date: Wed, 30 Dec 2020 17:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=93=E8=BE=91=E5=9B=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9Etype=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=B8=BAalbum=E6=97=B6=E8=A1=A8=E7=A4=BAfileName?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=BA=E4=B8=93=E8=BE=91=E5=90=8D=E8=80=8C?= =?UTF-8?q?=E9=9D=9E=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yutou/tools/home/nas/MusicController.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 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 e9f955f..6106341 100644 --- a/src/main/java/com/yutou/tools/home/nas/MusicController.java +++ b/src/main/java/com/yutou/tools/home/nas/MusicController.java @@ -107,8 +107,8 @@ public class MusicController { @ResponseBody public String findFile(@RequestBody JSONObject body) { String path = body.getString("path"); - if(!path.startsWith(defaultMusicPath)){ - path=Tools.base64ToString(path); + if (!path.startsWith(defaultMusicPath)) { + path = Tools.base64ToString(path); } JSONObject json = new JSONObject(); if (StringUtils.isEmpty(path)) { @@ -133,22 +133,37 @@ public class MusicController { json.put("code", 0); return json.toJSONString(); } - @RequestMapping(value = "web/image.do",produces = MediaType.IMAGE_JPEG_VALUE) + + @RequestMapping(value = "web/image.do", produces = MediaType.IMAGE_JPEG_VALUE) @ResponseBody - public byte[] getImage(String fileName){ - JSONObject json=new JSONObject(); - json.put("fileName",fileName); + public byte[] getImage(String fileName, String type) { + JSONObject json = new JSONObject(); + json.put("fileName", fileName); + if (StringUtils.isEmpty(type)) { + json.put("type", "file"); + } else { + json.put("type", type); + } return getImage(json); } - @RequestMapping(value = "image.do",produces = MediaType.IMAGE_JPEG_VALUE) + + @RequestMapping(value = "image.do", produces = MediaType.IMAGE_JPEG_VALUE) @ResponseBody public byte[] getImage(@RequestBody JSONObject body) { String fileName = body.getString("fileName"); - if(!fileName.startsWith(defaultMusicPath)){ - fileName=Tools.base64ToString(fileName); + if (!fileName.startsWith(defaultMusicPath)) { + fileName = Tools.base64ToString(fileName); } - File file=new File(fileName); - if(file.exists()){ + List list = null; + if (body.getString("type").equals("album")) { + list = musicTools.selectAlbum(fileName); + } + File file; + if (list != null && !list.isEmpty()) { + fileName = list.get(0).getFile(); + } + file = new File(fileName); + if (file.exists()) { try { return musicTools.readImage(file.getAbsolutePath()); } catch (Exception e) { @@ -179,11 +194,11 @@ public class MusicController { @RequestMapping("play.do") - public ResponseEntity play(String filePath,String random) { + public ResponseEntity play(String filePath, String random) { String _filePath; boolean _random; - _random= !StringUtils.isEmpty(random) && random.equals("true"); - _filePath=Tools.base64ToString(filePath); + _random = !StringUtils.isEmpty(random) && random.equals("true"); + _filePath = Tools.base64ToString(filePath); if (_random) { List list = musicTools.getMusicList(); MusicData data = list.get(Tools.randomCommon(0, list.size() - 1, 1)[0]);