在Recyclerview中使用videoview

时间:2016-04-22 15:35:14

标签: android android-recyclerview android-videoview

我想将videoview插入到我的recyclerview.I有视频网址,但是当我尝试这样做时,我在recyclelerview中看到了视频的黑色图。我想看视频而不是播放,只是停止了视频。 我的适配器:

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.VideoViewHolder> {
    List<Video> call;
    RecyclerViewAdapter(List<Video> call){
        this.call = call;

    }
    @Override
    public VideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_row,parent,false);
        VideoViewHolder videoViewHolder = new VideoViewHolder(v);
        return videoViewHolder;
    }

    @Override
    public void onBindViewHolder(VideoViewHolder holder, int position) {
        String video_url = call.get(position).getClipUrl();
        Log.d("Recycler Adapter", "videourl " + video_url);
holder.videoView.setVideoURI(Uri.parse(video_url));
        Log.d("Recycler Adapter", "title " + call.get(position).getTitle());
        Log.d("Recycler Adapter", "video_like " + call.get(position).getScore());

        holder.video_name.setText(call.get(position).getTitle());
        holder.video_like.setText(String.valueOf(call.get(position).getScore()));
    }

    @Override
    public int getItemCount() {
        return call.size();
    }

    public class VideoViewHolder extends RecyclerView.ViewHolder {
        CardView cardView;
        VideoView videoView;
        TextView video_name;
        TextView video_like;
        public VideoViewHolder(View itemView) {
            super(itemView);
            cardView = (CardView) itemView.findViewById(R.id.card_view);
            videoView = (VideoView)itemView.findViewById(R.id.videoview);
            video_name = (TextView) itemView.findViewById(R.id.Videoname_textView);
            video_like = (TextView) itemView.findViewById(R.id.like_textview);
        }
    }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

使用seek将它放在特定的第二个像这样:

videoView.seekTo(requiredTime);

requireTime是将要看到的图片的时间