VideoView overlaying another videoView on TabActivity Android

2

I have TabActivity with two Tabs , in both it has a VideoView (Man | Woman). When I start one of the Tabs and then switch to the other, the video of the first still runs under the other video. How can I resolve this?

Here is the code I'm using:

TabActivity

public class BarraTabActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost.newTabSpec("homem").setIndicator("Homem").setContent(new Intent(this, HomemActivity.class)));
    tabHost.addTab(tabHost.newTabSpec("mulher").setIndicator("Mulher").setContent(new Intent(this, MulherActivity.class)));
    tabHost.setCurrentTab(0);
}

Activity Man

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_homem);

    String path = "www.exemplo.com";

    Uri uri = Uri.parse(path);

    videoView = (VideoView) findViewById(R.id.vwHomem);
    videoView.setMediaController(new MediaController(this));
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();
}

Activity Woman

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mulher);

    String path = "www.exemplo.com";

    Uri uri = Uri.parse(path);

    videoView = (VideoView) findViewById(R.id.vwMulher);
    videoView.setMediaController(new MediaController(this));
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();
}

Layout (For men or women it's the same, just change the names)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <VideoView
        android:id="@+id/vwHomem" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2sp"
        android:layout_marginRight="2sp"
        android:layout_marginTop="2sp"/>

</RelativeLayout>
    
asked by anonymous 22.01.2015 / 13:45

2 answers

1

When the Homem or Mulher tabs are created, it is good to check if the other video not belonging to it is running, if it is, pause it and leave it invisible.

  

Woman Activity

@Override
protected void onCreate (Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mulher);

    String path = "www.exemplo.com";

    vwMen   = (VideoView) findViewById(R.id.vwMulher);
    vwWoman = (VideoView) findViewById(R.id.vwHomem);

    // setMediaController, setVideoUri e RequestFocus, mas ainda não inicie-o.
}

@Override
protected void onResume (){
    super.onResume();

    if(vwMen.isPlaying()) {
        vwMen.pause();
        vwMen.suspend();
        vwMen.setVisibility(INVISIBLE);
        vwWoman.start();

    } else vwWoman.start();
}

Do this in two activity , always checking to see if another video is running.

    
22.02.2015 / 14:49
0

Try calling the pause method in the onPause method of Activity.

@Override
public void onPause() {
    super.onPause();
    stopPosition = videoView.getCurrentPosition(); 
    videoView.pause();
}
@Override
public void onResume() {
    super.onResume();
    videoView.seekTo(stopPosition);
    videoView.start();
}
    
23.01.2015 / 05:21