背景:在清單(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;
}
}