I have a mediaplayer seekbar which is working fine until I rotate the screen. What I would like to see is the seekbar progress continue. However it resets to zero and no longer responds to touch event.
This is code in oncreate:
mSeekBar.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
seekChange(v);
return false;
}
});
And in main class:
private final Runnable updatePositionRunnable = new Runnable() {
public void run() {
updatePosition();
}
};
private void updatePosition() {
handler.removeCallbacks(updatePositionRunnable);
try{
if (mp != null) mSeekBar.setProgress(mp.getCurrentPosition());
} catch (Exception ex) {
mSeekBar.setProgress(0);
handler.removeCallbacks(updatePositionRunnable);
}
handler.postDelayed(updatePositionRunnable, 100);
}
//seekbar re-position track
private void seekChange(View v) {
try{
if (mp != null) mp.seekTo(mSeekBar.getProgress());
} catch (Exception ex) {
}
}
Any thoughts on what could be wrong?
Figured it out by myself in the end:
Add
android:configChanges="keyboardHidden|orientation"
to the Manifest for each activity you need to update.