我有两个包含两个不同内容的选项卡。
- Tab1->视频流
- Tab2->列表视图。
单击一个listview
项目时,我将转到详细信息页面activity
。按下后退时,它将移回listview
井中。但在后台,正在播放视频(Tab1 内容)。如何阻止这种情况?
我的代码:
...
public void onCreate(Bundle savedInstanceState) {
// sets the Bundle
super.onCreate(savedInstanceState);
// sets the context
setContentView(R.layout.videostream);
myVideoView = (VideoView) findViewById(R.id.vview);
mProgress = new ProgressDialog(this);
PlayVideo();
}
private void PlayVideo() {
try {
mProgress = ProgressDialog.show(VideoActivity.this, "",
"Buffering video...", true);
mProgress.setCancelable(true);
myVideoView.setVideoURI(Uri.parse(vSource));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mProgress.dismiss();
myVideoView.start();
}
});
} catch (Exception e) {
mProgress.dismiss();
System.out.println("Video Play Error :" + e.toString());
finish();
}
}
public void onSaveInstanceState(Bundle outState) {
mStartTime = myVideoView.getCurrentPosition();
outState.putInt("restartTime", mStartTime);
super.onSaveInstanceState(outState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
myInt = savedInstanceState.getInt("restartTime");
myVideoView.seekTo(myInt);
myVideoView.start();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// 2 means landscape and 1 means portait mode
if (newConfig.orientation == 2) {
mProgress.dismiss();
}
}
@Override
public void onPause() {
super.onPause();
myVideoView.stopPlayback();
}
@Override
public void onResume() {
super.onResume();
PlayVideo();
}