mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-03 23:52:09 +08:00
修复潜在问题与优化代码
This commit is contained in:
parent
754009b5bf
commit
9e7244c567
@ -12,7 +12,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class LyricPlayer {
|
public class LyricPlayer {
|
||||||
final String timeExp = "^\\[([\\d:.]*)\\]{1}";
|
final String timeExp = "^\\[([\\d:.]*)]";
|
||||||
// HashMap tagRegMap;
|
// HashMap tagRegMap;
|
||||||
Pattern timePattern;
|
Pattern timePattern;
|
||||||
|
|
||||||
@ -91,14 +91,14 @@ public class LyricPlayer {
|
|||||||
HashMap linesMap = new HashMap<String, HashMap>();
|
HashMap linesMap = new HashMap<String, HashMap>();
|
||||||
HashMap timeMap = new HashMap<String, Integer>();
|
HashMap timeMap = new HashMap<String, Integer>();
|
||||||
|
|
||||||
for (int i = 0; i < linesStr.length; i++) {
|
for (String lineStr : linesStr) {
|
||||||
|
String line = lineStr.trim();
|
||||||
String line = linesStr[i].trim();
|
|
||||||
Matcher result = timePattern.matcher(line);
|
Matcher result = timePattern.matcher(line);
|
||||||
if (result.find()) {
|
if (result.find()) {
|
||||||
String text = line.replaceAll(timeExp, "").trim();
|
String text = line.replaceAll(timeExp, "").trim();
|
||||||
if (text.length() > 0) {
|
if (text.length() > 0) {
|
||||||
String timeStr = result.group(1);
|
String timeStr = result.group(1);
|
||||||
|
if (timeStr == null) continue;
|
||||||
String[] timeArr = timeStr.split(":");
|
String[] timeArr = timeStr.split(":");
|
||||||
String hours;
|
String hours;
|
||||||
String minutes;
|
String minutes;
|
||||||
@ -115,18 +115,19 @@ public class LyricPlayer {
|
|||||||
minutes = timeArr[0];
|
minutes = timeArr[0];
|
||||||
seconds = timeArr[1];
|
seconds = timeArr[1];
|
||||||
break;
|
break;
|
||||||
default: return;
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (seconds.indexOf(".") > -1) {
|
if (seconds.contains(".")) {
|
||||||
timeArr = seconds.split("\\.");
|
timeArr = seconds.split("\\.");
|
||||||
seconds = timeArr[0];
|
seconds = timeArr[0];
|
||||||
milliseconds = timeArr[1];
|
milliseconds = timeArr[1];
|
||||||
}
|
}
|
||||||
HashMap<String, Object> lineInfo = new HashMap<String, Object>();
|
HashMap<String, Object> lineInfo = new HashMap<String, Object>();
|
||||||
int time = Integer.valueOf(hours) * 60 * 60 * 1000
|
int time = Integer.parseInt(hours) * 60 * 60 * 1000
|
||||||
+ Integer.valueOf(minutes) * 60 * 1000
|
+ Integer.parseInt(minutes) * 60 * 1000
|
||||||
+ Integer.valueOf(seconds) * 1000
|
+ Integer.parseInt(seconds) * 1000
|
||||||
+ Integer.valueOf(milliseconds);
|
+ Integer.parseInt(milliseconds);
|
||||||
lineInfo.put("time", time);
|
lineInfo.put("time", time);
|
||||||
lineInfo.put("text", text);
|
lineInfo.put("text", text);
|
||||||
lineInfo.put("translation", "");
|
lineInfo.put("translation", "");
|
||||||
@ -137,8 +138,8 @@ public class LyricPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] translationLines = translationLyric.split("\n");
|
String[] translationLines = translationLyric.split("\n");
|
||||||
for (int i = 0; i < translationLines.length; i++) {
|
for (String translationLine : translationLines) {
|
||||||
String line = translationLines[i].trim();
|
String line = translationLine.trim();
|
||||||
Matcher result = timePattern.matcher(line);
|
Matcher result = timePattern.matcher(line);
|
||||||
if (result.find()) {
|
if (result.find()) {
|
||||||
String text = line.replaceAll(timeExp, "").trim();
|
String text = line.replaceAll(timeExp, "").trim();
|
||||||
|
@ -30,7 +30,7 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
|||||||
final private ReactApplicationContext reactContext;
|
final private ReactApplicationContext reactContext;
|
||||||
final private LyricEvent lyricEvent;
|
final private LyricEvent lyricEvent;
|
||||||
|
|
||||||
private int winWidth = 0;
|
// private int winWidth = 0;
|
||||||
|
|
||||||
private float lastX; //上一次位置的X.Y坐标
|
private float lastX; //上一次位置的X.Y坐标
|
||||||
private float lastY;
|
private float lastY;
|
||||||
@ -114,7 +114,7 @@ public class LyricView extends Activity implements View.OnTouchListener {
|
|||||||
|
|
||||||
DisplayMetrics outMetrics = new DisplayMetrics();
|
DisplayMetrics outMetrics = new DisplayMetrics();
|
||||||
windowManager.getDefaultDisplay().getMetrics(outMetrics);
|
windowManager.getDefaultDisplay().getMetrics(outMetrics);
|
||||||
winWidth = (int)(outMetrics.widthPixels * 0.92);
|
// winWidth = (int)(outMetrics.widthPixels * 0.92);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意,悬浮窗只有一个,而当打开应用的时候才会产生悬浮窗,所以要判断悬浮窗是否已经存在,
|
// 注意,悬浮窗只有一个,而当打开应用的时候才会产生悬浮窗,所以要判断悬浮窗是否已经存在,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user