视频不会显示在使用Toro视频库的网址的Recyclerview中

时间:2018-02-07 10:15:01

标签: android listview android-recyclerview video-streaming

我正在开发一个涉及使用改造来显示后端视频列表的项目,我想使用recyclerview在UI上显示带有一些数据的视频,我正在尝试使用TORO视频库来处理视频,但视频显示成功,而不是显示视频,视频空间是空白和黑色和其他信息。 我想要的是正确使用该库,如果我弄错了,或链接到您已经测试过的其他库,如果您之前已经使用过,或者如何在您自己的项目中执行此操作。

检查以下与库一起使用的适配器代码。

package com.theproject.allClass.adapters;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import com.bumptech.glide.Glide;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.klinker.android.simple_videoview.SimpleVideoView;
import com.theproject.R;
import com.theproject.allClass.api.model.AuditionRoom;
import com.theproject.allClass.api.model.Timeline;

import java.util.List;

import im.ene.toro.ToroPlayer;
import im.ene.toro.ToroUtil;
import im.ene.toro.exoplayer.SimpleExoPlayerViewHelper;
import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.widget.Container;

public class AuditionRoomAdapter extends RecyclerView.Adapter<AuditionRoomAdapter.ViewHolder> {

    private Context context;
    private List<AuditionRoom> data;

    public AuditionRoomAdapter(Context context, List<AuditionRoom> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.audition_timeline, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.username.setText(data.get(position).getUsername());
        holder.userPostText.setText(data.get(position).getUserMessage());
        holder.yes.setText(""+data.get(position).getYes_votes_count());
        holder.no.setText(""+data.get(position).getNo_votes_count());
        Glide.with(context).load(data.get(position).getUserProfilepicUrl()).into(holder.userProfilePic);
//        Glide.with(context).load(data.get(position).getUpload_file_url()).into(holder.userPostImage);
        holder.bind(Uri.parse(data.get(position).getUpload_file_url()));

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder implements ToroPlayer{

        TextView username;
        TextView userPostText;
        TextView yes;
        TextView no;
        ImageView userProfilePic;
        ImageView userPostImage;
        SimpleExoPlayerView playerView;
        SimpleExoPlayerViewHelper helper;
        Uri mediaUri;

        public ViewHolder(View itemView) {
            super(itemView);

            userProfilePic = itemView.findViewById(R.id.audition_user_profile_pic);
            username = itemView.findViewById(R.id.audition_user_name);
            userPostText =  itemView.findViewById(R.id.audition_user_post_text);
            //userPostImage = itemView.findViewById(R.id.audition_user_post_image);
            playerView = itemView.findViewById(R.id.player);

            yes =  itemView.findViewById(R.id.audition_yes_figure);
            no = itemView.findViewById(R.id.audition_no_figure);
        }

        @NonNull
        @Override
        public View getPlayerView() {
            return playerView;
        }

        @NonNull
        @Override
        public PlaybackInfo getCurrentPlaybackInfo() {
            return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
        }

        @Override
        public void initialize(@NonNull Container container, @Nullable PlaybackInfo playbackInfo) {
            if (helper == null) {
                helper = new SimpleExoPlayerViewHelper(container, this, mediaUri);
            }
            helper.initialize(playbackInfo);
        }

        @Override
        public void play() {
            if (helper != null) helper.play();
        }

        @Override
        public void pause() {
            if (helper != null) helper.pause();
        }

        @Override
        public boolean isPlaying() {
            return helper != null && helper.isPlaying();
        }

        @Override
        public void release() {
            if (helper != null) {
                helper.release();
                helper = null;
            }
        }

        @Override
        public boolean wantsToPlay() {
            return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.85;
        }

        @Override
        public int getPlayerOrder() {
            return getAdapterPosition();
        }

        @Override
        public void onSettled(Container container) {

        }

        // called from Adapter to setup the media
        void bind(Uri item) {
            if (item != null) {
                mediaUri = item;
            }
        }
    }
}

The result of the recyclerview with video not working 链接到github上的库     https://github.com/eneim/toro/

2 个答案:

答案 0 :(得分:0)

我能够通过将架构(http或https)添加到加载网址来解决问题,TORO库适合在回收站视图上显示视频,经过测试和确认。

答案 1 :(得分:0)

我遇到了相同的错误,但是我通过添加解决了该错误 Container而不是RecycerView

<im.ene.toro.widget.Container android:id="@+id/recyleVideo" android:layout_width="match_parent" android:layout_height="match_parent" />