【已解决】 使用GSYvideoplayer播放框架,安卓客户端图片、视频混合轮播,切换过程出现黑屏,有没有好的解决方法?
karweny
2023-03-20 15:52 82
/**
* 视频+图片轮播处理代码
*/
private VideoHolder currentVideoHolder = null;
private class BannerPageChange implements OnPageChangeListener {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
//选中页面
@Override
public void onPageSelected(int position) {
mPosition = position ;
if (adapter != null){
currentVideoHolder = null;
//如果当前页不是视频类型
if (list.get(position).viewType != 2) {
adapter.stopVideo();
if (videoPlayRunnable != null) mHandler.removeCallbacks(videoPlayRunnable);
startScroll(mPageChangeMillis);
}else {
//视频类型,且仅有一个视频,自动重播
if (list.size() == 1)
playVideo(0, position);
else {
playVideo(mVideoPlayLoadWait, position+1);
}
Log.d(TAG,"开始播放----->" + position + 1);
stopScroll();
}
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
}
//当前position(显示出来的position,非真实position
private int mPosition = 0;
private Handler mHandler = new Handler();
//轮播切换的runnable
private Runnable runnable = new Runnable() {
@Override
public void run() {
mHandler.removeCallbacks(runnable);
banner.setCurrentItem(banner.getCurrentItem() + 1 , true);
}
};
//控制视频播放
private Runnable videoPlayRunnable;
private void playVideo(long millis, int position){
if (videoPlayRunnable != null) mHandler.removeCallbacks(videoPlayRunnable);
videoPlayRunnable = new Runnable(){
@Override
public void run() {
if (position == 1 && list.size() > 1 && banner.getCurrentItem() != 1){
banner.setCurrentItem(1, false);
return;
}
VideoHolder videoHolder = adapter.getVideoHolder(position);
if (videoHolder == null) {
showToast("获取视频播放控件出错");
return;
}
videoHolder.player.onVideoReset();
videoHolder.player.startPlayLogic();
videoHolder.player.setVideoAllCallBack(new GSYSampleCallBack(){
@Override
public void onAutoComplete(String url, Object... objects) {
super.onAutoComplete(url, objects);
if (position == 0) videoHolder.player.startPlayLogic();
else startScroll(0);
}
});
currentVideoHolder = videoHolder;
}
};
mHandler.postDelayed(videoPlayRunnable, millis);
}
你先默认选中你的视频播放页面,先确定有播放,如果播放了,就看看播放的日志输出。