I am creating an android music player.I am going to make both the Next and Forward button work in one button depending on the duration it's held down. In a short press it works as the Next button and in long press it works as the forward button. I have tried this using onLongClickListener but what happen is, it stops forwarding even before the user holds up the button. How do I implement it in the way where the action doesn't stop till the user hold up the button? Here is my code. Thanks in advanced.
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;
}
});
See this post of mine Events for Long click down and long click up in Android
If you want to detect touch events, which is called MotionEvent in Android, you have to override onTouchEvent(MotionEvent e) method and use GestureDetector class for identifying long press.
on long press down you can start a thread doing same in a loop and stop on long press up , hope this helps you