我想在播放 4 秒后暂停我的视频播放,然后我想向用户弹出一条消息。有人可以直接指出我如何在 4 秒后暂停视频吗?谢谢
V2实现了@gogothebee 反馈{现在视频在位置 0 处暂停(在它实际开始之前)。
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