I Want to pause my video play after 4 seconds of playing, then I want to pop up a message to the user. Can someone point me in the right direct how to pause the video after 4 seconds please. Thanks
V2 Implemented @gogothebee feedback {Now the video pause at position 0 (before it actually start).
public class PlayVideoActivity extends ActionBarActivity {
public static final String TAG = PlayVideoActivity.class.getSimpleName();
Bundle bunde;
Intent intent;
String content_actual_content;
VarController vc = new VarController(PlayVideoActivity.this);
public ImageLoader imageLoader;
private VideoView mVideoView;
private MediaController mMediaController;
ProgressBar pbplay1;
private boolean isActive;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_video); //playvideo (FullScreen)
handler = new Handler();
//Hide Action Bar
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
//Toast.makeText(PlayVideoActivity.this, "You're on Video Player with link: " + content_actual_content, Toast.LENGTH_SHORT).show();
//Set ProgressBar
pbplay1 = (ProgressBar) findViewById(R.id.pbplay1);
//Get Link from ImageAdapter
intent = this.getIntent();
bunde = intent.getExtras();
content_actual_content = bunde.getString("content_actual_content");
Toast.makeText(PlayVideoActivity.this, "You're on Video Player with link: " + content_actual_content, Toast.LENGTH_SHORT).show();
//Initiate Player
mVideoView = (VideoView) findViewById(R.id.videoview);
mVideoView.setVideoURI(Uri.parse(content_actual_content));
mVideoView.setMediaController(new MediaController(PlayVideoActivity.this));
mVideoView.requestFocus();
mVideoView.setMediaController(mMediaController);
//new myAsync().execute();
}//--- end onCreate
@Override
protected void onPause() {
super.onPause();
isActive = false;
}
@Override
protected void onResume() {
super.onResume();
isActive = true;
mVideoView.requestFocus();
mVideoView.start();
scheduleVideoPause(4000);
}
private void scheduleVideoPause(int msec) {
handler.removeCallbacksAndMessages(null);
handler.postDelayed(new Runnable() {
@Override
public void run() {
if(!isActive) {
return;
}
mVideoView.pause();
Toast.makeText(PlayVideoActivity.this, "Video has PAUSED at: " + mVideoView.getCurrentPosition(), Toast.LENGTH_SHORT).show();
}
}, msec);
}
V1
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_video); //playvideo (FullScreen)
//Hide Action Bar
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
//Toast.makeText(PlayVideoActivity.this, "You're on Video Player with link: " + content_actual_content, Toast.LENGTH_SHORT).show();
//Set ProgressBar
pbplay1 = (ProgressBar) findViewById(R.id.pbplay1);
//Get Link from ImageAdapter
intent = this.getIntent();
bunde = intent.getExtras();
content_actual_content = bunde.getString("content_actual_content");
Toast.makeText(PlayVideoActivity.this, "You're on Video Player with link: " + content_actual_content, Toast.LENGTH_SHORT).show();
//Initiate Player
mVideoView = (VideoView) findViewById(R.id.videoview);
mVideoView.setVideoURI(Uri.parse(content_actual_content));
mMediaController = new MediaController(PlayVideoActivity.this);
mVideoView.setMediaController(mMediaController);
mVideoView.requestFocus();
mVideoView.start();
//new myAsync().execute();
Log.i("**********************", "getCurrentPosition: " + mVideoView.getCurrentPosition());
if (mVideoView.getCurrentPosition() == 4000) {
mVideoView.pause();
Toast.makeText(PlayVideoActivity.this, "Video has PAUSED at: " + mVideoView.getCurrentPosition(), Toast.LENGTH_SHORT).show();
}
}//--- end onCreate