Question

I am having two tabs to show two different TV channels, but when I switch between tabs, their activity(intent) keep running, and they mix up. how can I make sure one channel stops playing before the new one starts?

Here is the code for Activity class:

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();
    }
}
Was it helpful?

Solution 2

I've solved it by overriding onPause method, looks like the activity goes to the Pause mode before displaying the new intent.

@Override
public void onPause() {
    super.onPause();
    videoView.stopPlayback();
    videoView.setVisibility(2);
}

OTHER TIPS

Hey, I think I got the solution for this::

Do this when you switch between tabs.

Intent intent= new Intent().setClass(this,SecondClass.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

And then do this...

tabHost.addTab(tabHost.newTabSpec("ABCD") .setIndicator(tabIndicator(...).setContent(intent));

Its mean whenever you will switch from the Tabs then Intent.FLAG_ACTIVITY_CLEAR_TOP creates new view for you...

Cheers...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top