我在列表视图中设置了onItemClickListener,其中包括视频,图像和文本。当用户在列表视图中点击视频时,它可以正常播放。现在,在playVideo()方法内部,将listview设置为null,以便用户在播放时不应与视频进行交互。
我想重获/ RESE丁字裤的onitemClicklisterner到真正的视频结束播放后。我该如何实施,请协助。
private void playVideo() {
listOfMessages.setOnItemClickListener(null);
videoText.setVideoURI(Uri.parse(chattVideo));
frameText.setVisibility(View.VISIBLE);
imageVideo.setVisibility(View.INVISIBLE);
videoText.setVisibility(View.VISIBLE);
btnText.setVisibility(View.GONE);
try {
videoText.setMediaController(mediaControllerText);
mediaControllerText.show();
videoText.seekTo(1);
videoText.pause();
videoText.stopPlayback();
videoText.seekTo(1);
videoText.resume();
progressBarMessage.setVisibility(View.GONE);
videoText.start();
videoText.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
progressBarMessage.setVisibility(View.GONE);
mp.start();
}
});
}
});
videoText.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
listOfMessages.setOnItemClickListener(this);// if I do like this android studio complains it cannot be applied inside MediaPlayer.OnCompletionListener
btnText.setVisibility(View.VISIBLE);
}
});
videoText.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
FancyToast.makeText(getContext(),"Something went wrong!",FancyToast.LENGTH_LONG,
FancyToast.ERROR,R.drawable.wheel,false).show();
return false;
}
});
} catch (Exception e) {
PBar.setVisibility(View.GONE);
FancyToast.makeText(getContext(),e.getMessage(),
FancyToast.LENGTH_LONG,FancyToast.WARNING,R.drawable.wheel,false).show();
}
}
问题来源:Stack Overflow
您可以按照以下方法创建所需内容
这是伪代码
private void setListener(boolean isPlaying){
if(isPlaying){
your_listview.setOnItemClickListener(null);
}
else{
your_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//YOUR CODE
}
});
}
}
现在,只需setListener(true)在视频播放时 调用setListener(false)
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。