我希望视频在屏幕向上滚动时停止播放。 我为此使用addOnScrollListener。
public boolean scrolldurum;
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// mScrollState = scrollState;
if(newState == RecyclerView.SCROLL_STATE_IDLE ) {
Toast.makeText(getActivity(),"scrol stop",Toast.LENGTH_SHORT).show();
scrolldurum = false;
Log.e("scrolldurumburcu", String.valueOf(scrolldurum));
}
if(newState == RecyclerView.SCROLL_STATE_DRAGGING ) {
Toast.makeText(getActivity(),"scrol START",Toast.LENGTH_SHORT).show();
scrolldurum = true;
Log.e("scrolldurumburcu", String.valueOf(scrolldurum));
}
super.onScrollStateChanged(recyclerView, newState);
}
});
我的布尔变量在屏幕滚动时为true,在停止时为false。 但是视频停止代码仅在onBindViewHolder中有效。
@Override
public void onBindViewHolder(final KelimelerAdapterx.CardTasarimTutucu holder, int position) {
final Kelimeler kelime = kelimelerListe.get(position);
holder.textViewIngilizce.setText(kelime.getAkis());
holder.textViewTurkce.setText(kelime.getLikebtn());
if (scrolldurum = true){
Log.e("xaxaxaxax", String.valueOf(scrolldurum));
holder.videoView.pause();
}
if (scrolldurum = false){
Log.e("xaxaxaxax", String.valueOf(scrolldurum));
}
holder.videoView.setErrorTracker(new SimpleVideoView.VideoPlaybackErrorTracker() {
@Override
public void onPlaybackError(Exception e) {
e.printStackTrace();
// Snackbar.make(holder.videoView, "Uh oh, error playing!", Snackbar.LENGTH_INDEFINITE).show();
holder.videoView.start("https://goldgym.pro/imga/"+holder.textViewTurkce.getText().toString());
holder. videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ( holder.videoView.isPlaying()) {
holder.videoView.pause();
}
else{
holder.videoView.play();
}
}
});
}
});
holder.videoView.start("https://goldgym.pro/imga/"+holder.textViewTurkce.getText().toString());
holder. videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ( holder.videoView.isPlaying()) {
Log.e("scrolldurumburcussss", String.valueOf(scrolldurum));
holder.videoView.pause();
} else {
holder.videoView.play();
}
}
});
}
我的布尔变量需要一个侦听器。 我怎样才能做到这一点。 如果您想查看我的完整代码。 https://gist.github.com/prensmiskin/161741f6e497a9d624258bedbddfd9d8