我想在互联网上播放videoView中的视频,所以我编写了如下所示的xml代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardElevation="11dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:clickable="true" />
<TextView
android:id="@+id/textViewDescriptionVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/videoView"
android:layout_marginLeft="13dp"
android:layout_marginStart="13dp"
android:text="Problem Description"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewAddressVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textViewDescriptionVideo"
android:layout_alignStart="@+id/textViewDescriptionVideo"
android:layout_below="@+id/textViewDescriptionVideo"
android:text="Address" />
<TextView
android:id="@+id/textViewDistanceVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/videoView"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="Distance" />
<RatingBar
android:id="@+id/ratingBarVideo"
style="@style/Widget.AppCompat.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textViewDistanceVideo"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/textViewTotalRVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textViewDescriptionVideo"
android:text="Total Rating" />
</RelativeLayout>
</android.support.v7.widget.CardView>
收听VideoView onTouch事件的代码如下所示
video_Holder.videoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
try {
currentPost = recievedList.get(video_Holder.getAdapterPosition());
progressDialog = ProgressDialog.show(context, "", "Buffering Video", false);
progressDialog.setCancelable(true);
mediacontroller = new MediaController(context);
Uri videoUri = Uri.parse(currentPost.getDownloadLink());
video_Holder.videoView.setMediaController(mediacontroller);
video_Holder.videoView.setVideoURI(videoUri);
video_Holder.videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
progressDialog.dismiss();
video_Holder.videoView.start();
}
});
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
return true;
}
});
因为我已将videoView的宽度设置为match_parent,所以为什么 它(videoView)显示不正确?