Exoplayer w Reyclerview

głosy
0

Jestem nowy z Exoplayer, im próbuje napisać klasę Exoplayer a następnie użyć go do Recyclerview że używam w moich activitys.

Na przykład, że posiadają aktywność, która ma Recyclerview

KOD

    public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.VideoViewHolder>{
    private LayoutInflater inflater;
    private Context context;
    private List<Video> data;

    public VideoListAdapter(Context context, List<Video> data){
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.data = data;
    }

    @Override
    public VideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = inflater.inflate(R.layout.video_item,parent,false);
        return new VideoViewHolder(v);
    }

    @Override
    public void onBindViewHolder(final VideoViewHolder holder, final int position) {
        final Video video = data.get(position);
        String videoIDCheck = video.getVideoID();
        if(!(videoIDCheck.equals(null) || videoIDCheck.equals() || videoIDCheck.isEmpty())) {
            MediaController mc = new MediaController(getContext());
            holder.tvTitleVideo.setText(video.getVideoName());
            holder.tvLikes.setText(String.valueOf(video.getLikes()));
            holder.tvViews.setText(String.valueOf(video.getViews()));
            holder.tvCommentsCount.setText(String.valueOf(video.getCountComments()));
            holder.tvUploadDate.setText(String.valueOf(timeAgo.getTimeAgo(video.getUploadDate(),getContext())));

            Uri uri = Uri.parse(video.getVideoURL());
            Log.d(MyPlayListFragment, URL  + uri.toString() +  position:  + position);
            holder.videoViewUser.setVideoURI(uri);
            mc.setAnchorView(holder.videoViewUser);
            holder.videoViewUser.requestFocus();
            holder.videoViewUser.setMediaController(mc);

            holder.ivThumbnailVideo.setVisibility(View.VISIBLE);
            Glide.with(getContext()).load(video.getFrameURL()).into(holder.ivThumbnailVideo);

            //edit the name of the video
            holder.tvTitleVideo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    changeVideoName(video.getVideoID(), holder.tvTitleVideo);
                }
            });
            holder.ibDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    deleteVideo(video.getVideoID(), video.getGenre().toLowerCase(), video.getVideoName(), video.getVideoURL(),position);
                }
            });

            //show comments
            holder.tvComments.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.d(TAG, tv comments clicked);
                    CommentsFragmentRV comments = new CommentsFragmentRV();
                    comments.setCancelable(true);
                    Bundle bundle = new Bundle();

                    bundle.putString(Params.VIDEOID, video.getVideoID());
                    bundle.putString(Params.GENRE, video.getGenre());
                    comments.setArguments(bundle);
                    comments.show(getFragmentManager(), TAG);
                }
            });
        }

    }

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


    public class VideoViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView tvTitleVideo,tvLikes,tvViews,tvUploadDate,tvComments,tvCommentsCount;
        private VideoView videoViewUser;
        private ImageView ivThumbnailVideo;
        private ImageButton ibDelete;

        public VideoViewHolder(View itemView) {
            super(itemView);
            tvTitleVideo = (TextView) itemView.findViewById(R.id.videoTitle);
            tvComments = (TextView)itemView.findViewById(R.id.tvCommentsMylist);
            tvCommentsCount = (TextView)itemView.findViewById(R.id.tvCommentsCount);
            tvLikes = (TextView)itemView.findViewById(R.id.tvLikes);
            tvViews = (TextView)itemView.findViewById(R.id.tvViews);
            videoViewUser = (VideoView)itemView.findViewById(R.id.videoViewUser);
            ivThumbnailVideo = (ImageView)itemView.findViewById(R.id.ivThumbnailVideo);
            ibDelete = (ImageButton)itemView.findViewById(R.id.ibDelete);
            tvUploadDate = (TextView)itemView.findViewById(R.id.tvUploadDate);

            ivThumbnailVideo.setOnClickListener(this);
        }

Jest to Reyclerview że używa „VideoView”. Instend VideoView chcę używać Exoplayer. Moje pytanie brzmi, czy jest możliwe, aby napisać klasę, a cały kod Exoplayer napisać tam iw Recyclerview zadzwonić tej klasy. Chcę napisać metod Exoplayer tylko raz i używać go na wiele działań.

Moje główne pytanie, czy jest możliwe, aby utworzyć klasę Exoplayer, w jaki sposób można go używać na Recyclerview?

Utwórz 10/10/2019 o 00:57
źródło użytkownik
W innych językach...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more