背景:在列表(ListView, RecyclerView)中使用GSYVideoPlayer播放视频时,闪退报错the sensor listeners size has exceeded the maximum limit 128。 原因是因为多个视频控件在初始化时,均调用了OrientationUtils(activity, gsyVideoPlayer); 进入代码查看,该工具类实例化时即绑定了监听,而系统传感器同时监听的数据是有限制的,导致了上面这个报错。
解决方案:每次调用OrientationUtils实例化方法前,手动释放了上一个视频的监听即可。可以使用如下方法。
public class VideoUtil {
private OrientationUtils orientationUtils = null;
private static VideoUtil videoUtil = null;
public synchronized static OrientationUtils getInstance(Activity activity, GSYBaseVideoPlayer gsyVideoPlayer) {
if (videoUtil == null) {
videoUtil = new VideoUtil();
}
if (videoUtil.orientationUtils != null) {
videoUtil.orientationUtils.releaseListener();
}
videoUtil.orientationUtils = new OrientationUtils(activity, gsyVideoPlayer);
return videoUtil.orientationUtils;
}
}