We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我是使用 RecyclerView 来实现的,Activity 布局中有一个 RecyclerView,RecyclerView 的每个 Item 都是一个 VideoPlayerView,然后使用 PagerSnapHelper 来实现类似于抖音一样的功能
Adapter 代码如下:
public class Adapter extends RecyclerView.Adapter<VideoViewHolder> { private Context context; private ArrayList<VideoBean> list; public Adapter(Context context, ArrayList<VideoBean> list) { this.context = context; this.list = list; } @NonNull @Override public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(context).inflate(R.layout.view___play_video_viewpager_item, parent, false); return new VideoViewHolder(itemView); } @Override public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) { String videoUrl = "list.get(position).getVideoUser()+"/" + list.get(position).getSourceFileName(); holder.bindData(videoUrl); String coverUrl = "list.get(position).getVideoUser() + "/cover/" + list.get(position).getCoverFileName(); holder.setPreImage(context,coverUrl); } @Override public int getItemCount() { return list.size(); } }
ViewHolder 代码如下:
public class VideoViewHolder extends RecyclerView.ViewHolder { private ExoUserPlayer userPlayer; private VideoPlayerView playerView; public VideoViewHolder(@NonNull View itemView) { super(itemView); playerView = itemView.findViewById(R.id.video_view); userPlayer = new VideoPlayerManager.Builder(VideoPlayerManager.TYPE_PLAY_USER, playerView).setDataSource(new PlayVideoDataSource(itemView.getContext())).create(); } public void setPreImage(Context context, String imageUrl) { Glide.with(context).load(imageUrl).into(playerView.getPreviewImage()); } public void bindData(String string) { userPlayer.setPlayUri(string); } }
代码可以正常运行,我想要实现抖音那样,进入Activity之后会自动播放,所以我尝试在 Activity 当中获取 VideoPlayer ,然后再调用它的 startPlayer 方法:
VideoPlayerManager instance = VideoPlayerManager.getInstance(); ExoUserPlayer videoPlayer = instance.getVideoPlayer(); videoPlayer.startPlayer();
但是 videoPlayer 为空,请问是什么原因啊,是我使用的方法哪里出错了吗?
我的依赖版本如下: implementation 'com.ycjiang:VideoPlayModule:2.3.61' implementation 'com.google.android.exoplayer:extension-okhttp:2.9.5'
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我是使用 RecyclerView 来实现的,Activity 布局中有一个 RecyclerView,RecyclerView 的每个 Item 都是一个 VideoPlayerView,然后使用 PagerSnapHelper 来实现类似于抖音一样的功能
Adapter 代码如下:
ViewHolder 代码如下:
代码可以正常运行,我想要实现抖音那样,进入Activity之后会自动播放,所以我尝试在 Activity 当中获取 VideoPlayer ,然后再调用它的 startPlayer 方法:
但是 videoPlayer 为空,请问是什么原因啊,是我使用的方法哪里出错了吗?
我的依赖版本如下:
implementation 'com.ycjiang:VideoPlayModule:2.3.61'
implementation 'com.google.android.exoplayer:extension-okhttp:2.9.5'
The text was updated successfully, but these errors were encountered: