gpt4 book ai didi

java - Android MediaPlayer实时快进和快退按钮使用runnable实现

转载 作者:行者123 更新时间:2023-12-02 05:16:09 26 4
gpt4 key购买 nike

我需要这方面的帮助,但没有真正找到明确的说明。如何创建一个按钮来快进和快退当前保留的歌曲。

最佳答案

private Handler repeatUpdateHandler = new Handler();
public int mValue; //increment
private boolean mAutoIncrement = false; //for fast foward in real time
private boolean mAutoDecrement = false; // for rewind in real time



private class RptUpdater implements Runnable {
public void run() {
if( mAutoIncrement ){
mValue += 30; //change this value to control how much to forward
mediaPlayer.seekTo(getCurrentPosition()+ mValue);
repeatUpdateHandler.postDelayed( new RptUpdater(), 50 );
} else if( mAutoDecrement ){
mValue -= 30; //change this value to control how much to rewind
seekTo(getCurrentPosition()- mValue);
repeatUpdateHandler.postDelayed( new RptUpdater(), 50 );
}
}
}



btnPrev.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
v.setPressed(true);
mAutoDecrement = true;
repeatUpdateHandler.post( new RptUpdater() );
return false;
}
else if(event.getAction() == MotionEvent.ACTION_UP) {
v.setPressed(false);
if( (event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL)
&& mAutoDecrement ){
mAutoDecrement = false;
}
return false;
}
return false;
}
});

btnNext.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
v.setPressed(true);
mAutoIncrement = true;
repeatUpdateHandler.post( new RptUpdater() );
return false;
}
else if(event.getAction() == MotionEvent.ACTION_UP) {
v.setPressed(false);
if( (event.getAction()==MotionEvent.ACTION_UP || event.getAction()==MotionEvent.ACTION_CANCEL)
&& mAutoIncrement ){
mAutoIncrement = false;
}
return false;
}

return false;
}
});

关于java - Android MediaPlayer实时快进和快退按钮使用runnable实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26942375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com