Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加弹幕倍速功能 #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,36 @@
package master.flame.danmaku.danmaku.model;

public class DanmakuTimer {
public long currMillisecond;

public long currMillisecond = 0L;
private long lastInterval;

public DanmakuTimer() {
private float videoSpeed = 1.0f;
private long lastTimeStamp = 0L;
private long lastCurr;
private long firstCurr;

public DanmakuTimer() {
}

public DanmakuTimer(long curr) {
update(curr);
}

public long update(long curr) {
lastInterval = curr - currMillisecond;
currMillisecond = curr;
if(lastTimeStamp == 0) {
lastTimeStamp = System.currentTimeMillis();
firstCurr = curr;
}
long t = System.currentTimeMillis();
lastInterval = t - lastTimeStamp;

if((lastInterval - curr + lastCurr) > 2000 || (lastInterval - curr + lastCurr) < -2000)
currMillisecond = curr - firstCurr;
else
currMillisecond += lastInterval * videoSpeed;

lastCurr = curr;
lastTimeStamp = t;
return lastInterval;
}

Expand All @@ -43,4 +58,11 @@ public long lastInterval() {
return lastInterval;
}

public void setSpeed(float speed) {
videoSpeed = speed;
}

public float getSpeed() {
return videoSpeed;
}
}