赞
踩
如果这个播放器用来recycleView中,实现类似抖音的效果,会发现刷了一段时间,会出现只有声音没有画面的情况。这个时候是因为surface没有创建(具体原因未知)。GSYTextureView中的onSurfaceTextureAvailable方法没有回调。
其他人也遇到过
GSYTextureRenderView onSurfaceAvailable 不调用(已添加硬件加速) #1740
如果发现surface没有创建成功就手动调用。继承StandardGSYVideoPlayer 重写以下四个方法
public class TRSVideoPlayer extends StandardGSYVideoPlayer { boolean isSurfaceAvailable; @Override protected void setProgressAndTime(int progress, int secProgress, int currentTime, int totalTime, boolean forceChange) { super.setProgressAndTime(progress, secProgress, currentTime, totalTime, forceChange); //以下代码要解决的问题是,如果这个播放器用来recycleView中,实现类似抖音的效果 //会发现刷了一段时间,会出现只有声音没有画面的情况。这个时候是因为surface没有创建(具体原因未知) //通过调用requestLayout可以创建surface。但是只在当前控件上调用requestLayout不起作用 //需要一直往上调用。 if (getCurrentState() == CURRENT_STATE_PLAYING || getCurrentState() == CURRENT_STATE_PLAYING_BUFFERING_START) { if (!isSurfaceAvailable) { Debuger.printfLog("VideoView 播放器缓冲中 isAddRenderView " + isSurfaceAvailable + " 当前播放器状态 " + getCurrentState()); try { requestLayoutLoop(this); } catch (Exception | OutOfMemoryError e) { onCompletion(); } return; } } } //一直循环向上调用。 private void requestLayoutLoop(Object obj){ if(obj==null){ return; } if(!(obj instanceof View)){ return; } View view= (View) obj; view.requestLayout(); requestLayoutLoop(view.getParent()); } @Override protected void addTextureView() { super.addTextureView(); //每次添加TextrueView就重置状态 isSurfaceAvailable = false; } @Override public void onSurfaceAvailable(Surface surface) { super.onSurfaceAvailable(surface); isSurfaceAvailable = true; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。