From 2e84e799d424b50155151ffc23de7c6c6b4db260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E7=9A=AE?= <14840170+lao-pi123@user.noreply.gitee.com> Date: Thu, 26 Sep 2024 09:40:53 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=9B=B8=E5=BF=83=E7=BE=8E=E9=A2=9CS?= =?UTF-8?q?o=E6=96=87=E4=BB=B6=E9=9D=99=E9=BB=98=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8B=E8=BD=BD=E5=A4=B1=E8=B4=A5=E3=80=81?= =?UTF-8?q?=E8=A7=A3=E5=8E=8B=E5=A4=B1=E8=B4=A5=E9=87=8D=E8=AF=95=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E5=92=8C=E5=A4=9A=E6=AC=A1=E5=A4=B1=E8=B4=A5=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../phonelive/activity/LauncherActivity.java | 57 ++++++++++++------- .../com/yunbao/common/CommonAppConfig.java | 4 ++ common/src/main/res/values-zh/strings.xml | 1 + common/src/main/res/values/strings.xml | 1 + .../live/activity/LiveSwAnchorActivity.java | 6 +- .../yunbao/main/activity/MainActivity.java | 5 +- .../main/dialog/MainStartDialogFragment.java | 9 ++- 7 files changed, 56 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java index 39055c622..5afc36436 100644 --- a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java +++ b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java @@ -186,19 +186,17 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL //解压后的文件数量必须要有2个 //如果文件存在,解压后 文件数量一致,直接进入下一步 if (fileSo.exists() && getFileCount(fileSoList.getAbsolutePath()) == 2){ - MainActivity.faceSDKIsLoadSuceness = true; + CommonAppConfig.faceSDKIsLoadSuceness = true; mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000); return; } // https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-arm64-v8a.zip - String soUrl = String.format("https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-%s.zip", cpuAbi); - Log.i("download", soUrl); - + downLoadFaceSDK_OutputDir = outputDir.getAbsolutePath(); if (!fileSo.exists()) { - downloadSo(outputDir.getAbsolutePath(), soUrl,Constants.FaceUnity_SO_Name,false); + downloadSo(downLoadFaceSDK_OutputDir, downLoadFaceSDK_downloadUrl,Constants.FaceUnity_SO_Name,false); }else if (fileSo.exists() && getFileCount(outputDir.getAbsolutePath()) < 3) { fileSo.delete(); - downloadSo(outputDir.getAbsolutePath(), soUrl,Constants.FaceUnity_SO_Name,false); + downloadSo(outputDir.getAbsolutePath(), downLoadFaceSDK_downloadUrl,Constants.FaceUnity_SO_Name,false); } } @@ -244,9 +242,13 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL } } - Dialog progressDialog; + private Dialog progressDialog; public ProgressBar progressBar; public TextView tvProgress; + private int downLoadFaceSDKCount = 0; + private int unZipFaceSDKCount = 0; + private String downLoadFaceSDK_OutputDir; + private String downLoadFaceSDK_downloadUrl = String.format("https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-%s.zip", Build.CPU_ABI); private void showDialog(Activity context) { progressDialog = new Dialog(context, com.yunbao.common.R.style.dialog); @@ -268,6 +270,9 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL progressDialog.setCancelable(false); progressDialog.show(); } + + + public void downloadSo(String outputDir, String downloadUrl,String fileName,boolean isShowDialog) { DownloadUtil downloadUtil = new DownloadUtil(); if(isShowDialog){ @@ -280,17 +285,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL progressDialog.dismiss(); mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 20); } - File fileSo = new File(outputDir, fileName); - try { - unzip(fileSo.getAbsolutePath(), outputDir); - MainActivity.faceSDKIsLoadSuceness = true; - if (BuildConfig.DEBUG){ - ToastUtil.showDebug("美颜SDK加载成功..."); - } - } catch (Exception e) { - Log.e("ZipCheck", "Error reading ZIP file", e); - throw new RuntimeException(e); - } + unZipFaceSDK(outputDir, fileName); } @Override @@ -304,12 +299,36 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL @Override public void onError(Throwable e) { //资源下载失败 - + downLoadFaceSDKCount++; + if (downLoadFaceSDKCount < 3) { + downloadSo(downLoadFaceSDK_OutputDir, downLoadFaceSDK_downloadUrl,Constants.FaceUnity_SO_Name,false); + } else { + CommonAppConfig.faceSDKDownLoadOrUnZipFailed = true; + } } }); } + private void unZipFaceSDK(String outputDir, String fileName) { + File fileSo = new File(outputDir, fileName); + try { + unzip(fileSo.getAbsolutePath(), outputDir); + } catch (Exception e) { + Log.e("ZipCheck", "Error reading ZIP file", e); + unZipFaceSDKCount++; + if (unZipFaceSDKCount < 3) { + unZipFaceSDK(outputDir, fileName); + } else { + CommonAppConfig.faceSDKDownLoadOrUnZipFailed = true; + } + } + CommonAppConfig.faceSDKIsLoadSuceness = true; + if (BuildConfig.DEBUG){ + ToastUtil.showDebug("美颜SDK加载成功..."); + } + } + /** * 解压 .zip 文件到目标目录 */ diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index ddc9390bd..6002b2e80 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -145,6 +145,10 @@ public class CommonAppConfig { private int mAppIconRes; private String mAppName; private Boolean mTiBeautyEnable;//是否使用萌颜 true使用萌颜 false 使用基础美颜 + // 美颜SDK是否已经加载成功 + public static boolean faceSDKIsLoadSuceness; + // 美颜SDK是否下载失败或者解压失败(自动试3次) + public static boolean faceSDKDownLoadOrUnZipFailed = false; public String getUid() { if (TextUtils.isEmpty(mUid)) { diff --git a/common/src/main/res/values-zh/strings.xml b/common/src/main/res/values-zh/strings.xml index e599f31ea..059c891ae 100644 --- a/common/src/main/res/values-zh/strings.xml +++ b/common/src/main/res/values-zh/strings.xml @@ -827,6 +827,7 @@ 暫時只對主播開放 請稍等,美顏SDK加載中 + 美顏SDK加載失敗,請重啟App 2011402032399020 959584e054a33614996361f0044e5253 diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 2b2f2598b..5eb0c4aef 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -787,6 +787,7 @@ For the time being, it is only open to the anchor Please wait, the beauty SDK is loading. + Beauty SDK failed to load, please restart the App 2011402032399020 959584e054a33614996361f0044e5253 diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index eab9047b3..dc1a3eb10 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -215,14 +215,14 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl super.main(); Bus.getOn(this); Intent intent = getIntent(); - if(CommonAppConfig.IS_GOOGLE_PLAY == 0){ + /* if(CommonAppConfig.IS_GOOGLE_PLAY == 0){ // 美颜SO设置 File file_FaceUnity = new File(mContext.getDir("lib", Context.MODE_PRIVATE).getAbsoluteFile(), com.yunbao.common.Constants.DOWNLOAD_FaceUnity_SO + File.separator + Build.CPU_ABI); faceunity.LoadConfig.loadLibrary(file_FaceUnity.getAbsolutePath()); Log.i("downLoad", "美颜SO Path = " + file_FaceUnity.getAbsolutePath()); - } + }*/ - initFaceManager(); +// initFaceManager(); leave_img = findViewById(R.id.leave_img); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); if (mLiveSDK == Constants.LIVE_SDK_SW) { diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index f5ecdf256..ca58d3c25 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -205,10 +205,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene private View floatWarOrder;//战令浮窗 private List startListNotifyList = new ArrayList<>(); - private String[] libNameList = new String[]{"agora-core", "agora-ffmpeg", "agora-fdkaac", "agora-soundtouch","agora-rtc-sdk"}; - // 美颜SDK是否已经加载成功 - public static boolean faceSDKIsLoadSuceness = false; - +// private String[] libNameList = new String[]{"agora-core", "agora-ffmpeg", "agora-fdkaac", "agora-soundtouch","agora-rtc-sdk"}; @Override protected int getLayoutId() { diff --git a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java index aa9da03dd..457172654 100644 --- a/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java +++ b/main/src/main/java/com/yunbao/main/dialog/MainStartDialogFragment.java @@ -168,11 +168,18 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O public void onLiveClick() { boolean isAnchor = IMLoginManager.get(mContext).getUserInfo().anchorUserType(); if (isAnchor) { + if (CommonAppConfig.faceSDKDownLoadOrUnZipFailed){ + // 美颜SDK下载或解压失败并且重试三次还是失败,提示用户重启 + ToastUtil.show(getString(R.string.face_sdk_load_failed)); + return; + } + // 判断美颜SDK是否加载成功 - if (!MainActivity.faceSDKIsLoadSuceness){ + if (!CommonAppConfig.faceSDKIsLoadSuceness){ ToastUtil.show(getString(R.string.wait_face_sdk_load)); return; } + String[] permissions; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { permissions = new String[]{