From e407dd1f335aa9c716b89b3152bf363b898d28fa Mon Sep 17 00:00:00 2001 From: Runt <qingingrunt2010@qq.com> Date: Sun, 29 May 2022 11:29:56 +0000 Subject: [PATCH] 接口请求框架 注册接口 --- app/src/main/java/com/auto/lyric/data/LyricServer.java | 33 ++++++++++++++++----------------- 1 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/auto/lyric/data/LyricServer.java b/app/src/main/java/com/auto/lyric/data/LyricServer.java index 8b8ef7e..7b47db2 100644 --- a/app/src/main/java/com/auto/lyric/data/LyricServer.java +++ b/app/src/main/java/com/auto/lyric/data/LyricServer.java @@ -6,7 +6,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Iterator; import java.util.List; import java.util.TreeMap; import java.util.regex.Matcher; @@ -18,6 +17,7 @@ public class LyricServer { + // key 时间戳 , obj 歌词 private static TreeMap<Integer, LyricObject> lrc_map = new TreeMap<>(); public static TreeMap<Integer, LyricObject> getLrc_map() { @@ -68,18 +68,22 @@ // System.out.println("++++++++++++>>"+data); /*text = text.replace("[","");//将前面的替换成后面的 text = text.replace("]","@"); - String splitdata[] = text.split("@");//分隔*/ + String splitdata[] = text.split("@");//分隔 String regex = "(?<=\\])"; Pattern compile = Pattern.compile(regex); - String[] splitdata = compile.split(text,2);//分隔 - if(text.endsWith("]") || splitdata.length == 1){ - - String str = text; - str = str.replace("[",""); - str = str.replace("]",""); - str = str.replace(":","."); - str = str.replace(".","@"); - String timedata[] =str.split("@"); + String[] splitdata = compile.split(text,2);//分隔*/ + int index = text.indexOf("]"); + String[] splitdata; + if(text.length()-1 == index){ + splitdata = new String[]{text}; + }else{ + splitdata = new String[]{text.substring(0,index),text.substring(index+1)}; + } + String tmpstr = splitdata[0].replace("[","").replace("]",""); + if(splitdata.length == 1){ + tmpstr = tmpstr.replace(":","."); + tmpstr = tmpstr.replace(".","@"); + String timedata[] =tmpstr.split("@"); Matcher matcher = pattern.matcher(timedata[0]); if(timedata.length==3 && matcher.matches()){ int m = Integer.parseInt(timedata[0]); //分 @@ -93,9 +97,6 @@ } } else{ String lrcContenet = splitdata[1]; - String tmpstr = splitdata[0]; - tmpstr = tmpstr.replace("[",""); - tmpstr = tmpstr.replace("]",""); tmpstr = tmpstr.replace(":","."); tmpstr = tmpstr.replace(".","@"); String timedata[] =tmpstr.split("@"); @@ -118,7 +119,6 @@ */ private static void initLrc(TreeMap<Integer, LyricObject> lrc_read){ lrc_map.clear(); - Iterator<Integer> iterator = lrc_read.keySet().iterator(); LyricObject oldval = null; int i =0; for(Integer key : lrc_read.keySet()){ @@ -126,8 +126,7 @@ if (oldval == null) { oldval = val; } else { - LyricObject item1= new LyricObject(); - item1 = oldval; + LyricObject item1 = oldval; item1.timeline = val.begintime-oldval.begintime; lrc_map.put(new Integer(i), item1); i++; -- Gitblit v1.9.1