【发布时间】:2018-12-26 17:57:17
【问题描述】:
我需要在加载时将图像从 uri 获取到我的 VideoView 中。当播放被击中时,它应该消失并开始播放视频。这是我的 VideoView 代码 -
<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>
这就是我的使用方式-
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);
}
}
});
【问题讨论】: