I am trying to show VideoView on top of SurfaceView . But this is not visible, but responds to clicks (MediaController appears and sound is played). It seems that the video is playing behind SurfaceView , so I also tried using setZOrderMediaOverlay() and / or setZOrderOnTop() , but nothing changed
When I go to the main screen, I see the VideoView for a second in the fading animation, so it really is present.
I tried it with xml layout as well as fully software, but nothing works.
Here is my activity:
public class VideoTest extends Activity { private RelativeLayout mLayout; private VideoView mVideo; private Handler mHandler; private FrameLayout mFrameLayout; private SurfaceView mSurfaceView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFrameLayout = new FrameLayout(this); mFrameLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mLayout = new RelativeLayout(this); mLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mVideo = new VideoView(this); mVideo.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mSurfaceView = new SurfaceView(this); mSurfaceView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); mSurfaceView.setZOrderMediaOverlay(false); mSurfaceView.setZOrderOnTop(false); mFrameLayout.addView(mSurfaceView); mLayout.addView(mVideo); mFrameLayout.addView(mLayout); setContentView(mFrameLayout);
My xml:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_reader" android:layout_width="fill_parent" android:layout_height="fill_parent"> <SurfaceView android:id="@+id/surface_view" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <RelativeLayout android:id="@+id/videoview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone"> <VideoView android:id="@+id/video_view" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> </FrameLayout>
One hint: since this is just a test to find out why it doesnβt work, I tried to minimize the code from my real application, where the visibility of the VideoView controlled by a handler that receives a message from drawing the SurfaceView thread. That is why I implemented a thread sending a message when the menu was used.
android visibility videoview surfaceview
Warren faith
source share