I need to get an image from a uri into my VideoView when it loads. It should disappear and start playing the video when play is hit. This is my VideoView code -
<RelativeLayout
android:id="@+id/video_frame"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:background="#000"
>
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
/>
<ImageButton
android:id="@+id/play_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_media_play"
/>
</RelativeLayout>
This is how I use it -
final VideoView video = (VideoView) convertView.findViewById(R.id.video);
Uri uri = Uri.parse(submission.getUrl());
video.setVideoURI(uri);
final ImageButton playButton = (ImageButton) convertView.findViewById(R.id.play_button);
video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
playButton.setVisibility(View.VISIBLE);
}
});
playButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (video.isPlaying()){
}else{
video.start();
playButton.setVisibility(View.GONE);
}
}
});
VideoViewshows a video. It does not show an image. Similarly,ImageViewshows an image. It does not show a video.So, use a
FrameLayoutwrapped around anImageViewand aVideoView. Have theImageViewbe visible and theVideoViewbe invisible at the outset. Load the image into theImageView. When the user clicks your play button, switch the visibility such that theVideoViewis now visible and theImageViewis invisible, and start playback of your video.