jiecao第三方视频框架的简单集成和使用

github网址:https://github.com/open-android/JieCaoVideoPlayer

1. 在project的build.gradle添加如下代码(如下图)

jiecao第三方视频框架的简单集成和使用_第1张图片

2. 在Module的build.gradle添加依赖

  compile 'com.github.open-android:JieCaoVideoPlayer:0.1.0'

3.添加权限




4.在Activity中添加如下代码

listView = (ListView) findViewById(R.id.listview);
adapterVideoList = new VideoListAdapter(this);
listView.setAdapter(adapterVideoList);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorEventListener = new JCVideoPlayer.JCAutoFullscreenListener();
5.适配器
package com.example.a2.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.a2.R;
import com.example.a2.view.bean.VideoDataBean;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;
import com.squareup.picasso.Picasso;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by Administrator on 2018/6/16.
 */

public class VideoAdapter extends RecyclerView.Adapter {
    public static final String TAG = "JieCaoVideoPlayer";

    List list;
    Context context;
    private View view;

    public VideoAdapter(Context context) {
        this.context = context;
    }

    public VideoAdapter(Context context, List data) {
        this.context = context;
        list = data;
        Fresco.initialize(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder holder = null;
        view = View.inflate(context, R.layout.videoitem, null);
            holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.videoitem_img_headportrait.setImageURI(list.get(position).getProfile_image());

        holder.videoitem_text_username.setText(list.get(position).getName());
        holder.videoitem_text_time.setText(list.get(position).getPasstime());
        holder.videoitem_text_title.setText(list.get(position).getText());

        holder.videoplayer.setUp(
                list.get(position).getVideouri(), JCVideoPlayer.SCREEN_LAYOUT_LIST);
        System.out.println("fdsfdsfdsfdsfa setup " + position);
        Picasso.with(view.getContext())
                .load(list.get(position).getBimageuri())
                .into(holder.videoplayer.thumbImageView);
        holder.videoitem_text_lovenum.setText(list.get(position).getLove());

        holder.videoitem_text_hatenum.setText(list.get(position).getHate());
        holder.videoitem_text_commentnum.setText(list.get(position).getComment());
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

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

    class ViewHolder extends RecyclerView.ViewHolder{

        SimpleDraweeView videoitem_img_headportrait;
        TextView videoitem_text_username;
        TextView videoitem_text_time;
        TextView videoitem_text_title;
        JCVideoPlayerStandard videoplayer;
        Button videoitem_but_love;
        Button videoitem_but_hate;
        Button videoitem_but_share;
        Button videoitem_but_comment;
        TextView videoitem_text_lovenum;
        TextView videoitem_text_hatenum;
        TextView videoitem_text_commentnum;

        public ViewHolder(View itemView) {
            super(itemView);
            videoitem_img_headportrait = itemView.findViewById(R.id.videoitem_img_headportrait);
            videoitem_text_username = itemView.findViewById(R.id.videoitem_text_username);
            videoitem_text_time = itemView.findViewById(R.id.videoitem_text_time);
            videoitem_text_title = itemView.findViewById(R.id.videoitem_text_title);
            videoplayer = itemView.findViewById(R.id.videoplayer);
            videoitem_but_love = itemView.findViewById(R.id.videoitem_but_love);
            videoitem_but_hate = itemView.findViewById(R.id.videoitem_but_hate);
            videoitem_but_share = itemView.findViewById(R.id.videoitem_but_share);
            videoitem_but_comment = itemView.findViewById(R.id.videoitem_but_comment);
            videoitem_text_lovenum = itemView.findViewById(R.id.videoitem_text_lovenum);
            videoitem_text_hatenum = itemView.findViewById(R.id.videoitem_text_hatenum);
            videoitem_text_commentnum = itemView.findViewById(R.id.videoitem_text_commentnum);
        }
    }
}

你可能感兴趣的:(移动开发)