Reputation: 2171
Many posts are there for this issue.But the solutions are available for when the activity gets paused. I tried all it doesn't work. My problem is little bit different
I have a videoview and when the user clicks the videoview ,video will be paused and if he clicks again it should be resumed.
My code snippet in ontouchlistener is,
videopath = getIntent().getStringExtra("path");
imageView = ((VideoView) findViewById(R.id.imageView));
imageView.setVideoPath(videopath);
imageView.start();
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_UP)
if (layout.getVisibility()==View.VISIBLE) {
imageView.seekTo(stopPosition);
imageView.resume();
layout.animate().translationY(-layout.getHeight()).setDuration(500);
layout.setVisibility(View.GONE);
hideSystemUI();
} else {
imageView.pause();
stopPosition=imageView.getCurrentPosition();
showSystemUI();
layout.setVisibility(View.VISIBLE);
layout.animate().translationYBy(layout.getHeight());
}
return true;
}
});
I got this solution from this link . It doesn't work and simply using resume(); is also not working.
Upvotes: 1
Views: 1347
Reputation: 2067
This happens because your device looses the time you've stored. You can use MediaPlayer instance, Here how you can use,
VideoView videoView;
MediaPlayer mp;
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
this.mp = mp;
}
});
public void pause(){
//NOT videoview.pause();
if (mp != null){
mp.pause();
}
}
public void resume(){
//NOT videoview.resume();
if (mp != null){
mp.start();
}
}
//This function will be implemented under onClick method
if (!videoView.isPlaying()) {
resume();
layout.setVisibility(View.GONE);
hideSystemUI();//hiding navigationbar
}
else {//initially layout visibility is GONE
pause();
stopPosition=videoView.getCurrentPosition();
showSystemUI();
layout.setVisibility(View.VISIBLE);
layout.animate().translationYBy(layout.getHeight());
}
Upvotes: 3