OK, thatβs how I solved it. The layout file is pretty simple. Just add an ImageButton after the VideoView element:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <FrameLayout android:id="@+id/video_frame" android:layout_width="fill_parent" android:layout_height="480px" android:background="#000" > <VideoView android:id="@+id/video_view" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <ImageButton android:id="@+id/play_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:src="@drawable/ic_launcher" /> </FrameLayout>
The FrameLayout view item splits its children into each other, in the order they are defined in the layout. Thus, the last element added to the layout is drawn on top. Note that ImageButton has this attribute:
android:layout_gravity="center_vertical|center_horizontal"
This attribute centers the ImageButton in the FrameLayout.
The next trick is to make ImageButton disappear after clicking it. To do this, use the setVisibility () method in ImageButton:
// Setup a play button to start the video mPlayButton = (ImageButton) findViewById(R.id.play_button); mPlayButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mPlayer.isPlaying()) { resetPlayer(); } else { playVideo(videoUrl, mVideoView.getHolder()); // show the media controls mController.show(); // hide button once playback starts mPlayButton.setVisibility(View.GONE); } } });
Joe fernandez
source share