写一个长按3倍速的java代码
时间: 2023-03-15 13:36:10 浏览: 229
public class LongPressThreeTimesSpeed {
public static void main(String[] args) {
// 获取当前系统开始时间
long startTime = System.currentTimeMillis();
while(System.currentTimeMillis() - startTime < 3000){
// 当前系统时间减去开始时间小于3000表示长按3秒
}
// 如果长按3秒,需要执行的操作
System.out.println("3倍速");
}
}
相关问题
写一个ijkplayer的长按3倍速java代码
public class IjkPlayer {
private long mDuration;
private long mPosition;
private int mSpeed; public IjkPlayer(long duration, long position, int speed) {
this.mDuration = duration;
this.mPosition = position;
this.mSpeed = speed;
}
public void setSpeed(int speed) {
this.mSpeed = speed;
}
public void longPress3Speed() {
mPosition = mPosition + ((mDuration - mPosition) / mSpeed) * 3;
}
}
写一个长按3倍速播放的java代码
public void playAt3XSpeed(String musicFile){
File file = new File(musicFile);
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate() * 3,
false);
AudioInputStream din = AudioSystem.getAudioInputStream(decodedFormat, in);
try {
SourceDataLine line = AudioSystem.getSourceDataLine(decodedFormat);
line.open(decodedFormat);
line.start();
int nByte = 0;
byte[] buffer = new byte[4096];
while(nByte != -1){
nByte = din.read(buffer, 0, buffer.length);
if(nByte >= 0){
line.write(buffer, 0, nByte);
}
}
line.drain();
line.close();
} catch (LineUnavailableException | IOException e) {
e.printStackTrace();
}
}
阅读全文