优化下载直播插件流程
This commit is contained in:
parent
cef94a248e
commit
fd06243c22
@ -26,7 +26,6 @@ import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
||||
import com.shayu.phonelive.utils.LogUtils;
|
||||
import com.shayu.phonelive.utils.PluginManager;
|
||||
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
|
||||
import com.tencent.imsdk.v2.V2TIMManager;
|
||||
import com.tencent.imsdk.v2.V2TIMSimpleMsgListener;
|
||||
@ -249,7 +248,7 @@ public class AppContext extends CommonAppContext {
|
||||
configSPApp();
|
||||
//初始化美颜SDK
|
||||
// FaceManager.initFaceUnity(this);
|
||||
PluginManager.getInstance().loadAnchorPlugin();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,20 +1,22 @@
|
||||
package com.shayu.phonelive.utils;
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import static com.yunbao.faceunity.utils.FURenderer.BUNDLE_AI_FACE;
|
||||
import static com.yunbao.faceunity.utils.FaceUnityConfig.BUNDLE_FACE_BEAUTIFICATION;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yunbao.common.CommonAppContext;
|
||||
import com.yunbao.common.utils.DownloadUtil;
|
||||
import com.yunbao.common.utils.StringUtil;
|
||||
import com.yunbao.faceunity.utils.FileUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
@ -25,7 +27,7 @@ import java.util.zip.ZipInputStream;
|
||||
public class PluginManager {
|
||||
private static PluginManager manager;
|
||||
private static final String TAG = "插件管理器";
|
||||
private String anchorPluginDownloadUrl = "http://192.168.137.1:12345/shares/ce47aa99-3e73-4a79-8a2f-e17a2d527953";
|
||||
private String anchorPluginDownloadUrl = "http://nas.cnmglz.com:9999/apk/pluginsForAnchor-release.apk";
|
||||
|
||||
private PluginManager() {
|
||||
}
|
||||
@ -44,16 +46,20 @@ public class PluginManager {
|
||||
this.anchorPluginDownloadUrl = anchorPluginDownloadUrl;
|
||||
}
|
||||
|
||||
public boolean isDownloadApk() {
|
||||
return new File(CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin_download" + File.separator + "anchorPlugin.apk").exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载主播插件
|
||||
*/
|
||||
public void loadAnchorPlugin() {
|
||||
public void loadAnchorPlugin(DialogInterface.OnDismissListener dismissListener) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
if (Arrays.asList(CommonAppContext.sInstance.getAssets().list("")).contains("anchorPlugin.apk")) {
|
||||
FileUtils.copyAssetsFile(CommonAppContext.sInstance,"anchorPlugin.apk","anchorPlugin.apk",CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin_download");
|
||||
}
|
||||
copyAssetsFile(CommonAppContext.sInstance, "anchorPlugin.apk", "anchorPlugin.apk", CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin_download");
|
||||
Log.d(TAG, "解压assets下的文件");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -63,12 +69,15 @@ public class PluginManager {
|
||||
Log.e(TAG, "主播下载地址为空");
|
||||
return;
|
||||
}
|
||||
downloadAnchorSdk();
|
||||
downloadAnchorSdk(dismissListener);
|
||||
return;
|
||||
}
|
||||
String outDir = CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin";
|
||||
loadFaceSo(sdk, outDir);
|
||||
loadFaceBundle(sdk, outDir);
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
dismissListener.onDismiss(null);
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
@ -79,7 +88,9 @@ public class PluginManager {
|
||||
* @param outDir 解压路径
|
||||
*/
|
||||
private void loadFaceSo(File plugin, String outDir) {
|
||||
if(!new File(CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin"+File.separator+"lib").exists()) {
|
||||
unzip(plugin.getAbsolutePath(), outDir, ".so");
|
||||
}
|
||||
String[] abis = Build.SUPPORTED_ABIS;
|
||||
String abi = Arrays.asList(abis).contains("arm64-v8a") ? "arm64-v8a" : "armeabi-v7a";
|
||||
File plugins = new File(outDir + File.separator + "lib" + File.separator + abi);
|
||||
@ -94,9 +105,17 @@ public class PluginManager {
|
||||
* @param outDir 解压路径
|
||||
*/
|
||||
private void loadFaceBundle(File plugin, String outDir) {
|
||||
if(!new File(CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin"+File.separator+"assets").exists()) {
|
||||
unzip(plugin.getAbsolutePath(), outDir, ".bundle");
|
||||
BUNDLE_AI_FACE = outDir + File.separator + "assets" + File.separator + BUNDLE_AI_FACE;
|
||||
BUNDLE_FACE_BEAUTIFICATION = outDir + File.separator + "assets" + File.separator + BUNDLE_FACE_BEAUTIFICATION;
|
||||
}
|
||||
try {
|
||||
Object BUNDLE_AI_FACE = Class.forName("com.yunbao.faceunity.utils.FURenderer").getField("BUNDLE_AI_FACE").get(null);
|
||||
Object BUNDLE_FACE_BEAUTIFICATION = Class.forName("com.yunbao.faceunity.utils.FaceUnityConfig").getField("BUNDLE_FACE_BEAUTIFICATION").get(null);
|
||||
Class.forName("com.yunbao.faceunity.utils.FURenderer").getField("BUNDLE_AI_FACE").set(null, outDir + File.separator + "assets" + File.separator + BUNDLE_AI_FACE);
|
||||
Class.forName("com.yunbao.faceunity.utils.FaceUnityConfig").getField("BUNDLE_FACE_BEAUTIFICATION").set(null, outDir + File.separator + "assets" + File.separator + BUNDLE_FACE_BEAUTIFICATION);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,13 +137,13 @@ public class PluginManager {
|
||||
/**
|
||||
* 下载主播插件包
|
||||
*/
|
||||
private void downloadAnchorSdk() {
|
||||
private void downloadAnchorSdk(DialogInterface.OnDismissListener dismissListener) {
|
||||
String downloadDir = new File(CommonAppContext.sInstance.getFilesDir().getAbsolutePath() + File.separator + "plugin_download").getAbsolutePath();
|
||||
new DownloadUtil().download("plugin", downloadDir, "anchorPlugin.apk", anchorPluginDownloadUrl, new DownloadUtil.Callback() {
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
Log.d(TAG, "下载成功 " + file);
|
||||
loadAnchorPlugin();
|
||||
loadAnchorPlugin(dismissListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,4 +214,33 @@ public class PluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static String copyAssetsFile(Context context, String assetsPath, String fileName, String saveFileDir) {
|
||||
File fileDir = new File(saveFileDir);
|
||||
if (!fileDir.exists()) {
|
||||
fileDir.mkdirs();
|
||||
}
|
||||
File file = new File(fileDir, fileName);
|
||||
if (file.exists()) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
try {
|
||||
InputStream inputStream = context.getAssets().open(assetsPath);
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
byte[] byteArray = new byte[1024];
|
||||
int bytes = bis.read(byteArray);
|
||||
while (bytes > 0) {
|
||||
bos.write(byteArray, 0, bytes);
|
||||
bos.flush();
|
||||
bytes = bis.read(byteArray);
|
||||
}
|
||||
bos.close();
|
||||
fos.close();
|
||||
return file.getAbsolutePath();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import android.Manifest;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -23,6 +24,8 @@ import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.dialog.AbsDialogFragment;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.utils.DialogUitl;
|
||||
import com.yunbao.common.utils.PluginManager;
|
||||
import com.yunbao.common.utils.ProcessResultUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.live.LiveConfig;
|
||||
@ -213,7 +216,23 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O
|
||||
}
|
||||
};
|
||||
}
|
||||
if (PluginManager.getInstance().isDownloadApk()) {
|
||||
PluginManager.getInstance().loadAnchorPlugin(it -> {
|
||||
LiveHttpUtil.getLiveSdk(mGetLiveSdkCallback);
|
||||
});
|
||||
} else {
|
||||
DialogUitl.showSimpleDialog(mContext, "需要下载开播插件,是否下载", new DialogUitl.SimpleCallback() {
|
||||
@Override
|
||||
public void onConfirmClick(Dialog dialog, String content) {
|
||||
Dialog downloadDialog = DialogUitl.loadingDialog(mContext, "下载中");
|
||||
downloadDialog.show();
|
||||
PluginManager.getInstance().loadAnchorPlugin(it -> {
|
||||
LiveHttpUtil.getLiveSdk(mGetLiveSdkCallback);
|
||||
downloadDialog.dismiss();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
LiveAnchorActivity.forward(mContext, CommonAppConfig.LIVE_SDK_USED, LiveConfig.getDefaultKsyConfig());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user