Skip to content

Commit 0ef2554

Browse files
committed
歌词正常工作
1 parent 834eedc commit 0ef2554

6 files changed

Lines changed: 23 additions & 24 deletions

File tree

server/core/src/main/java/com/coloryr/allmusic/server/core/command/sub/CommandStop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void execute(Object sender, String name, String[] args) {
2020
AllMusic.side.sendMessage(sender, AllMusic.getMessage().musicPlay.stopPlaying);
2121
}
2222
AllMusic.side.sendStop(name);
23-
HudUtils.clearHud(name);
23+
HudUtils.sendClearHud(name);
2424
}
2525

2626
@Override

server/core/src/main/java/com/coloryr/allmusic/server/core/music/LyricSave.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Map;
77

88
public class LyricSave {
9-
public int lastIndex = 0;
109
protected boolean haveLyric;
1110
protected float kly = 0;
1211
protected LyricItemObj now;
@@ -51,29 +50,29 @@ public void kUpdate(long playNow) {
5150
if (now == null || now.lyric == null || now.lyric.isEmpty()
5251
|| ktvNow == null || ktvNow.items == null || ktvNow.items.isEmpty()) {
5352
kly = 0.0f;
53+
return;
54+
}
55+
56+
if (playNow < ktvNow.start) {
57+
kly = 0.0f;
58+
return;
59+
}
60+
61+
if (playNow >= ktvNow.start + ktvNow.time) {
62+
kly = 1.0f;
63+
return;
5464
}
5565

56-
// 查找当前时间落在哪个 KTV 字的时间段内
5766
for (int i = 0; i < ktvNow.items.size(); i++) {
5867
KtvLyric.KtvItem item = ktvNow.items.get(i);
5968
if (playNow >= item.start && playNow < item.start + item.time) {
60-
// 当前字内的进度
6169
float progressInChar = (float) (playNow - item.start) / item.time;
62-
// 整体进度 = (已完成的字 + 当前字的进度) / 总字数
6370
kly = (i + progressInChar) / ktvNow.items.size();
64-
lastIndex = i; // 记录当前字索引,可选
71+
return;
6572
}
6673
}
6774

68-
// 如果时间超过了最后一个字
69-
if (playNow >= ktvNow.start + ktvNow.time) {
70-
kly = 1.0f;
71-
lastIndex = ktvNow.items.size();
72-
}
73-
74-
// 还没到第一个字的时间
7575
kly = 0.0f;
76-
lastIndex = 0;
7776
}
7877

7978
private void ktvGetNext(long time) {
@@ -99,17 +98,13 @@ public boolean lyricGetNext(long playNow) {
9998
now.tlyric = "";
10099
}
101100
kly = 0.0f;
102-
lastIndex = 0;
103-
ktvGetNext(playNow);
104101
return true;
105102
}
106103

107104
return false;
108105
}
109106

110107
public void updateKtv(long playNow) {
111-
if (now != null) {
112-
kUpdate(playNow);
113-
}
108+
ktvGetNext(playNow);
114109
}
115110
}

server/core/src/main/java/com/coloryr/allmusic/server/core/music/PlayRuntime.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static void clear() {
7171
PlayMusic.lyric = null;
7272
PlayMusic.nowPlayMusic = null;
7373
AllMusic.side.updateInfo();
74-
HudUtils.clearHud();
74+
HudUtils.sendClearHud();
7575
HudUtils.sendHudNowData();
7676
HudUtils.sendHudLyricData();
7777
HudUtils.sendHudListData();
@@ -99,6 +99,10 @@ private static void time1() {
9999
if (res) {
100100
HudUtils.sendHudLyricData();
101101
AllMusic.side.updateLyric();
102+
if (AllMusic.getConfig().ktvMode) {
103+
PlayMusic.lyric.updateKtv(PlayMusic.musicNowTime);
104+
HudUtils.sendHudKtv();
105+
}
102106
}
103107

104108
if (AllMusic.getConfig().ktvMode) {
@@ -206,6 +210,7 @@ private static void musicPlayTask() {
206210
}
207211
Thread.sleep(1000);
208212
} else {
213+
HudUtils.sendClearHud();
209214
HudUtils.sendHudNowData();
210215
HudUtils.sendHudLyricData();
211216
HudUtils.sendHudListData();

server/core/src/main/java/com/coloryr/allmusic/server/core/objs/config/ConfigObj.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.coloryr.allmusic.server.core.objs.config;
22

3-
import com.coloryr.allmusic.codec.HudPosObj;
43
import com.coloryr.allmusic.server.core.AllMusic;
54

65
import java.util.HashMap;

server/core/src/main/java/com/coloryr/allmusic/server/core/utils/HudUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public static boolean setHudEnable(String player, HudType pos, String arg) {
248248
/**
249249
* 清空Hud数据
250250
*/
251-
public static void clearHud() {
251+
public static void sendClearHud() {
252252
AllMusic.side.clearHud();
253253
}
254254

@@ -257,7 +257,7 @@ public static void clearHud() {
257257
*
258258
* @param player 用户名
259259
*/
260-
public static void clearHud(String player) {
260+
public static void sendClearHud(String player) {
261261
AllMusic.side.clearHud(player);
262262
}
263263

0 commit comments

Comments
 (0)