修复调整播放速率时桌面歌词导致的崩溃问题

This commit is contained in:
lyswhut 2023-03-24 09:01:56 +08:00
parent 9d9e9e61ed
commit 5c44ffbc4a
3 changed files with 7 additions and 7 deletions

View File

@ -29,7 +29,7 @@ public class Lyric extends LyricPlayer {
String translationText = ""; String translationText = "";
String romaLyricText = ""; String romaLyricText = "";
Lyric(ReactApplicationContext reactContext, boolean isShowTranslation, boolean isShowRoma, int playbackRate) { Lyric(ReactApplicationContext reactContext, boolean isShowTranslation, boolean isShowRoma, float playbackRate) {
this.reactAppContext = reactContext; this.reactAppContext = reactContext;
this.isShowTranslation = isShowTranslation; this.isShowTranslation = isShowTranslation;
this.isShowRoma = isShowRoma; this.isShowRoma = isShowRoma;

View File

@ -20,7 +20,7 @@ public class LyricModule extends ReactContextBaseJavaModule {
boolean isShowTranslation = false; boolean isShowTranslation = false;
boolean isShowRoma = false; boolean isShowRoma = false;
int playbackRate = 1; float playbackRate = 1;
private int listenerCount = 0; private int listenerCount = 0;
@ -87,7 +87,7 @@ public class LyricModule extends ReactContextBaseJavaModule {
} }
@ReactMethod @ReactMethod
public void setPlaybackRate(int playbackRate, Promise promise) { public void setPlaybackRate(float playbackRate, Promise promise) {
this.playbackRate = playbackRate; this.playbackRate = playbackRate;
if (lyric != null) lyric.setPlaybackRate(playbackRate); if (lyric != null) lyric.setPlaybackRate(playbackRate);
promise.resolve(null); promise.resolve(null);

View File

@ -27,7 +27,7 @@ public class LyricPlayer {
List<HashMap> lines = new ArrayList<>(); List<HashMap> lines = new ArrayList<>();
HashMap tags = new HashMap(); HashMap tags = new HashMap();
boolean isPlay = false; boolean isPlay = false;
int playbackRate = 1; float playbackRate = 1;
int curLineNum = 0; int curLineNum = 0;
int maxLine = 0; int maxLine = 0;
int offset = 150; int offset = 150;
@ -89,7 +89,7 @@ public class LyricPlayer {
} }
private int getCurrentTime() { private int getCurrentTime() {
return (getNow() - this.performanceTime) * this.playbackRate + startPlayTime; return (int)((getNow() - this.performanceTime) * this.playbackRate) + startPlayTime;
} }
private void initTag() { private void initTag() {
@ -297,7 +297,7 @@ public class LyricPlayer {
if (driftTime >= 0 || curLineNum == 0) { if (driftTime >= 0 || curLineNum == 0) {
HashMap nextLine = lines.get(curLineNum + 1); HashMap nextLine = lines.get(curLineNum + 1);
int delay = ((int) nextLine.get("time") - (int) curLine.get("time") - driftTime) / this.playbackRate; int delay = (int)(((int)nextLine.get("time") - (int)curLine.get("time") - driftTime) / this.playbackRate);
// Log.d("Lyric", "delay: " + delay + " driftTime: " + driftTime); // Log.d("Lyric", "delay: " + delay + " driftTime: " + driftTime);
if (delay > 0) { if (delay > 0) {
if (isPlay) { if (isPlay) {
@ -331,7 +331,7 @@ public class LyricPlayer {
init(); init();
} }
public void setPlaybackRate(int playbackRate) { public void setPlaybackRate(float playbackRate) {
this.playbackRate = playbackRate; this.playbackRate = playbackRate;
if (this.lines.size() == 0) return; if (this.lines.size() == 0) return;
if (!this.isPlay) return; if (!this.isPlay) return;