我有两个标签来显示两个不同的电视频道,但是当我在标签之间切换时,它们的活动(意图)会继续运行,并且它们会混淆。如何确保一个频道在新频道开始之前停止播放?
下面是 Activity 类的代码:
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
extras = getIntent().getExtras();
progressDialog = ProgressDialog.show(TvMenuOne.this, "TV1",
"Please Wait..", true, true);
PlayVideo();
}
private void PlayVideo() {
try {
videoView = (VideoView) findViewById(R.id.surface_view);
if(extras.getString("id").equals("one")){
videoView.setVideoPath(pathL);
}
if(extras.getString("id").equals("two")){
videoView.setVideoPath(pathM);
}
videoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
videoView.setMediaController(new MediaController(TvMenuOne.this));
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
} catch (Exception e) {
progressDialog.dismiss();
System.out.println("Video Play Error :" + e.toString());
finish();
}
}