diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java index b3f9742d7..c174f1492 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWAuManager.java @@ -98,16 +98,18 @@ public class SWAuManager extends BaseCacheManager { */ public void initRtcEngine(Activity mContext) { this.mContext = mContext; - try { - // 创建 RtcEngineConfig 对象,并进行配置 - RtcEngineConfig config = new RtcEngineConfig(); - config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; - config.mEventHandler = mRtcEventHandler; - // 创建并初始化 RtcEngine - mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); - } catch (Exception e) { - throw new RuntimeException("Check the error."); + if(mRtcEngine==null){ + try { + // 创建 RtcEngineConfig 对象,并进行配置 + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = mContext; + config.mAppId = CommonAppConfig.SWAPPId; + config.mEventHandler = mRtcEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); + } catch (Exception e) { + throw new RuntimeException("Check the error."); + } } mRtcEngine.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING); // 直播模式,引擎級別 // 开启本地预览 @@ -120,13 +122,15 @@ public class SWAuManager extends BaseCacheManager { public void initRtcEngineAudio(Activity mContext) { this.mContext = mContext; try { + if(mRtcEngine==null){ + RtcEngineConfig config = new RtcEngineConfig(); + config.mContext = mContext; + config.mAppId = CommonAppConfig.SWAPPId; + config.mEventHandler = mEventHandler; + // 创建并初始化 RtcEngine + mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); + } // 创建 RtcEngineConfig 对象,并进行配置 - RtcEngineConfig config = new RtcEngineConfig(); - config.mContext = mContext; - config.mAppId = CommonAppConfig.SWAPPId; - config.mEventHandler = mEventHandler; - // 创建并初始化 RtcEngine - mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config); mRtcEngine.enableAudio(); mRtcEngine.enableLocalAudio(true); } catch (Exception e) { @@ -417,7 +421,9 @@ public class SWAuManager extends BaseCacheManager { } public void preloadChannel(List uids){ + L.eSw("设置秒开数据"); for (int i = 0; i { private CommonRefreshView mRefreshView; private MainHomeRemFollLiveAdapter mAdapter; @@ -56,7 +59,7 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple mRefreshView.showRefreshBar(); mRefreshView.mRecyclerView.scrollToPosition(0); } - }else if ("blacklist".equals(str)) { + } else if ("blacklist".equals(str)) { if (mRefreshView != null) { mRefreshView.showRefreshBar(); } @@ -99,6 +102,7 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple @Override public void onRefreshSuccess(List list, int count) { + SWAuManager.get().preloadChannel(list); EventBus.getDefault().post(new AnchorRecommendModel()); } @@ -115,6 +119,7 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple new_data.add(loadItemList.get(j)); } } + SWAuManager.get().preloadChannel(new_data); mAdapter.insertList(new_data); } @@ -147,6 +152,9 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple // if (mRefreshView != null) { // mRefreshView.initData(); // } + if (mAdapter != null) { + SWAuManager.get().preloadChannel(mAdapter.getList()); + } } @Override @@ -164,6 +172,6 @@ public class MainHomeFollLiveViewHolder extends AbsMainHomeChildViewHolder imple @Override public void onResume() { super.onResume(); - + L.eSw("onResume"); } } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java index 0dfd0bc0f..88fc09831 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeFollowViewHolder.java @@ -23,6 +23,8 @@ import com.yunbao.main.http.MainHttpUtil; import java.util.List; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + /** * Created by cxf on 2018/9/22. * 首页 关注 @@ -70,7 +72,9 @@ public class MainHomeFollowViewHolder extends AbsMainHomeChildViewHolder impleme public List processData(String[] info) { if (info.length > 0) { JSONObject obj = JSON.parseObject(info[0]); - return JSON.parseArray(obj.getString("list"), LiveBean.class); + List liveBeanList = JSON.parseArray(obj.getString("list"), LiveBean.class); + SWAuManager.get().preloadChannel(liveBeanList); + return liveBeanList; } return null; } diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 0a8dc1a9c..2301f50be 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -74,6 +74,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + /** * Created by cxf on 2018/9/22. * MainActivity 首页 直播 @@ -242,6 +244,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement if (liveModel != null) { old_data.remove(liveModel); } + SWAuManager.get().preloadChannel(old_data); new_data.addAll(old_data); } @@ -271,6 +274,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement } } if (loadItemList.size() > 0) { + SWAuManager.get().preloadChannel(new_data); mAdapter.insertList(new_data); } } @@ -533,6 +537,9 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement @Override public void loadData() { + if (mAdapter != null) { + SWAuManager.get().preloadChannel(mAdapter.getList()); + } } @Override diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java index d86234c2f..ec5025544 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeRecomLiveViewHolder.java @@ -31,6 +31,8 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.Arrays; import java.util.List; +import io.agora.beautyapi.faceunity.agora.SWAuManager; + /** * 首页推荐 */ @@ -104,6 +106,7 @@ public class MainHomeRecomLiveViewHolder extends AbsMainHomeChildViewHolder impl @Override public void onRefreshSuccess(List list, int count) { + SWAuManager.get().preloadChannel(list); EventBus.getDefault().post(new AnchorRecommendModel()); } @@ -149,6 +152,9 @@ public class MainHomeRecomLiveViewHolder extends AbsMainHomeChildViewHolder impl // if (mRefreshView != null) { // mRefreshView.initData(); // } + if (mAdapter != null) { + SWAuManager.get().preloadChannel(mAdapter.getList()); + } } @Override