本文介绍了ExoPlayer PlayerView OnClickListener无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用中,我想处理用户单击PlayerView
的情况,但是未调用OnClickListener
,并且不会引发任何异常.我添加了app:use_controller="false"
到XML PlayerView
.
In my app, I want to handle user click on PlayerView
however OnClickListener
not being called and no exception is thrown. I added app:use_controller="false"
to XML PlayerView
.
我试图设置OnTouchListener
,但是我需要调用MotionEvent.ACTION_UP
,这也没有发生(因为我不想在用户滚动时处理这种情况,所以我需要在用户滚动时处理这种情况点按PlayerView).
I tried to set OnTouchListener
but I need MotionEvent.ACTION_UP
to be called which is also not happening(because I don't want to handle the case when the user is scrolling, I need to handle the case when the user taps on PlayerView).
class FeedHolder extends RecyclerView.ViewHolder {
private TextView displayName, jobTitle, action, date, likedBy;
private ImageIndicator profile_pic;
private ImageView videoOptions, likeImage, shareImage;
private PlayerView playerView;
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
FeedHolder(View itemView) {
super(itemView);
profile_pic = itemView.findViewById(R.id.profile_pic);
likedBy = itemView.findViewById(R.id.tv_like_by);
date = itemView.findViewById(R.id.tv_date);
likeImage = itemView.findViewById(R.id.img_like);
shareImage = itemView.findViewById(R.id.img_share);
displayName = itemView.findViewById(R.id.tv_display_name);
jobTitle = itemView.findViewById(R.id.tv_job_title);
action = itemView.findViewById(R.id.btn_action);
videoOptions = itemView.findViewById(R.id.video_options);
playerView = itemView.findViewById(R.id.exo_player);
webView = itemView.findViewById(R.id.web_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new AnimationWebViewClient());
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
}
@Override
public void onBindViewHolder(@NonNull FeedHolder holder, int position) {
holder.playerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
...
}
});
}
推荐答案
您可以使用:
video.setControllerAutoShow(false);
video.setUseController(false);
video.getVideoSurfaceView().setOnClickListener(view -> {
Log.e("GET", "clicked!");
if(player.getPlayWhenReady()){
player.setPlayWhenReady(false);
}else{
player.setPlayWhenReady(true);
}
});
这篇关于ExoPlayer PlayerView OnClickListener无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!