在android eclipse中将Next和Forward功能组合为一个按钮
我正在创建一个android音乐播放器。我将使下一个按钮和前进按钮在一个按钮中工作,这取决于按下的持续时间。短按时,它作为下一个按钮,长按时,它作为前进按钮。我尝试过使用onlongclicklister,但实际情况是,它甚至在用户按下按钮之前就停止了转发。我如何实现它,直到用户按下按钮,操作才会停止?这是我的密码。提前谢谢在android eclipse中将Next和Forward功能组合为一个按钮,android,audio-player,onlongclicklistener,android-music-player,Android,Audio Player,Onlongclicklistener,Android Music Player,我正在创建一个android音乐播放器。我将使下一个按钮和前进按钮在一个按钮中工作,这取决于按下的持续时间。短按时,它作为下一个按钮,长按时,它作为前进按钮。我尝试过使用onlongclicklister,但实际情况是,它甚至在用户按下按钮之前就停止了转发。我如何实现它,直到用户按下按钮,操作才会停止?这是我的密码。提前谢谢 btnNext.setOnLongClickListener(new OnLongClickListener() { @Override
btnNext.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
// get current song position
int currentPosition = mp.getCurrentPosition();
// check if seekForward time is lesser than song duration
if (currentPosition + seekForwardTime <= mp.getDuration()) {
// forward song
mp.seekTo(currentPosition + seekForwardTime + LONG_CLICK_LISTERNER_INTERVAL);
} else {
// forward to end position
mp.seekTo(mp.getDuration());
}
return true;
}
});
btnNext.setOnLongClickListener(新的OnLongClickListener(){
@凌驾
仅长按公共布尔值(视图arg0){
//获取当前歌曲位置
int currentPosition=mp.getCurrentPosition();
//检查seekForward时间是否小于歌曲持续时间
如果(currentPosition+seekForwardTime见我的这篇文章
如果您想要检测触摸事件(Android中称为MotionEvent),则必须重写onTouchEvent(MotionEvent e)方法并使用GestureDetector类识别长按
private GestureDetector mGestureDetector;
public FfwRewButton(...) {
//....
mGestureDetector = new GestureDetector(context,
new GestureDetector.SimpleOnGestureListener() {
public boolean onDown(MotionEvent e) {
mLongClicked = false;
return true;
}
public void onLongPress(MotionEvent e) {
mLongClicked = true;
// long press down detected
}
});
}
public boolean onTouchEvent(MotionEvent e) {
mGestureDetector.onTouchEvent(e);
if (mLongClicked && e.getAction() == ACTION_UP) {
// long press up detected
}
}
}
在长时间向下按压时,您可以在循环中启动一个线程并在长时间向上按压时停止,希望这对您有所帮助