**1.初始化MHSDK**
**新建****App****.java文件,在****onCreate****方法中添加以下代码**
```
MHSDK.getInstance().init(this," ");
```
**2.**** 初始化美颜界面**
**找到****VideoChatViewActivity****.java文件,继承****DefaultBeautyEffectListener****接口,添加以下变量:**
```
private Handler mHandler;
private AlertDialog dialog;
private RelativeLayout beautyContainer;
private MHBeautyManager mhBeautyManager;
private BaseBeautyViewHolder beautyViewHolder;
private boolean isResume;
private int retryCount;
private Thread beautyThread;
```
**添加以下方法:**
```
private void initBeautyView() {
if (MHSDK.getInstance().isVerEnd()){
setBeautyView();
}else {
if (beautyThread != null) {
beautyThread.interrupt();
beautyThread = null;
}
beautyThread = new BeautyThread(this);
beautyThread.start();
}
}
private void showRetryDialog() {
if (dialog != null) {
dialog.cancel();
}
SDKDialogListener diaLogListener = new SDKDialogListener(this);
dialog = new AlertDialog.Builder(this)
.setTitle("提示")
.setMessage("资源获取失败,请检查网络")
.setCancelable(false)
.setPositiveButton("确定", diaLogListener)
.create();
dialog.show();
}
private void showExitDialog() {
if (dialog != null) {
dialog.cancel();
}
DiaLogListener diaLogListener = new DiaLogListener(this);
dialog = new AlertDialog.Builder(this)
.setTitle("提示")
.setMessage("资源获取失败,请检查网络并退出重试")
.setCancelable(false)
.setPositiveButton("确定", diaLogListener)
.create();
dialog.show();
}
private void setBeautyView(){
LogManager.getInstance().writeData("MainActivity_setBeautyView_SDKVersion=" + MHSDK.getInstance().getVer());
if (!MHSDK.getInstance().isVerifyAccess()){
if (retryCount < 10) {
showRetryDialog();
}else {
showExitDialog();
return;
}
}
if (beautyViewHolder != null) {
beautyViewHolder.release();
beautyViewHolder = null;
}
beautyViewHolder = BeautyViewHolderFactory.getBeautyViewHolder(getApplicationContext(), beautyContainer);
beautyViewHolder.show();
beautyViewHolder.setEffectListener(this);
beautyViewHolder.setVisibleListener(visible -> {
if (!visible) {
beautyViewHolder.show();
}
});
beautyViewHolder.setMhBeautyManager(mhBeautyManager);
}
static class DiaLogListener implements DialogInterface.OnClickListener {
WeakReference activityWeakReference;
DiaLogListener(LiveChatActivity activity) {
this.activityWeakReference = new WeakReference<>(activity);
}
@Override
public void onClick(DialogInterface dialog, int which) {
LiveChatActivity activity = activityWeakReference.get();
if (activity == null)return;
switch (which){
case -1:
dialog.cancel();
activity.finish();
break;
case -2:
dialog.cancel();
break;
}
}
}
static class SDKDialogListener implements DialogInterface.OnClickListener {
WeakReference activityWeakReference;
SDKDialogListener(LiveChatActivity activity) {
this.activityWeakReference = new WeakReference<>(activity);
}
@Override
public void onClick(DialogInterface dialog, int which) {
LiveChatActivity activity = activityWeakReference.get();
if (activity == null)return;
switch (which){
case -1:
activity.retryCount ++;
MHSDK.getInstance().clearVerNote();
MHSDK.getInstance().verify("");
activity.initBeautyView();
dialog.cancel();
break;
case -2:
dialog.cancel();
break;
}
}
}
static class BeautyThread extends Thread {
WeakReference mainActivityWeakReference;
BeautyThread(LiveChatActivity txMainActivity) {
this.mainActivityWeakReference = new WeakReference<>(txMainActivity);
}
@Override
public void run() {
while (mainActivityWeakReference.get()!= null && !MHSDK.getInstance().isVerEnd()) {
if (isInterrupted()) return;
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
LiveChatActivity activity = mainActivityWeakReference.get();
if (activity != null){
activity.mHandler.post(activity::setBeautyView);
}
}
}
@Override
public void onFilterChanged(FilterBean filterBean) {
if (mhBeautyManager == null) {
return;
}
FilterEnum filterEnum = filterBean.getFilterEnum();
if (filterEnum == FilterEnum.PRO_FILTER) {
mhBeautyManager.changeDynamicFilter(filterBean.getmFilterName());
} else {
Bitmap lookupBitmap = BitmapUtil.getFilterBitmap(this,filterEnum);
mhBeautyManager.setFilter(lookupBitmap);
}
}
@Override
public void onMeiBaiChanged(int progress) {
if (mhBeautyManager != null) {
mhBeautyManager.setSkinWhiting(progress);
}
}
@Override
public void onMoPiChanged(int progress) {
if (mhBeautyManager != null) {
mhBeautyManager.setSkinSmooth(progress);
}
}
@Override
public void onFengNenChanged(int progress) {
if (mhBeautyManager != null) {
mhBeautyManager.setSkinTenderness(progress);
}
}
@Override
public void onBeautyOrigin() {
if (mhBeautyManager != null) {
mhBeautyManager.setSkinWhiting(0);
mhBeautyManager.setSkinSmooth(0);
mhBeautyManager.setSkinTenderness(0);
}
}
```
**在****onCreate****方法中调用****initBeautyView****方法。**
**3.**** 自定义渲染**
**在****VideoChatViewActivity****.java添加以下变量**
```
private GLSurfaceView mGLSurfaceViewLocal;
private VideoManager mVideoManager;
private SinkConnector mEffectHandler = new SinkConnector() {
@Override
public int onDataAvailable(VideoCaptureFrame data) {
int textureId = data.mTextureId;
int newTexture = textureId;
try {
if (mhBeautyManager == null) {
mhBeautyManager = new MHBeautyManager(getApplicationContext(),true);
mhBeautyManager.setBeautyDataModel(BeautyDataModel.getInstance());
if (beautyViewHolder != null) {
beautyViewHolder.setMhBeautyManager(mhBeautyManager);
}
}else{
newTexture = mhBeautyManager.render4(textureId, data.mFormat.mWidth, data.mFormat.mHeight);
}
} catch (Exception e) {
e.printStackTrace();
}
return newTexture;
}
};
```
**setupLocalVideo****方法改为以下代码**
```
private void setupLocalVideo() {
// This is used to set a local preview.
// The steps setting local and remote view are very similar.
// But note that if the local user do not have a uid or do
// not care what the uid is, he can set his uid as ZERO.
// Our server will assign one and return the uid via the event
// handler callback function (onJoinChannelSuccess) after
// joining the channel successfully.
// mLocalView = RtcEngine.CreateRendererView(getBaseContext());
// mLocalView.setZOrderMediaOverlay(true);
// mLocalContainer.addView(mLocalView);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// int height = displayMetrics.heightPixels/2;
// int width = displayMetrics.widthPixels/2;
// int height = displayMetrics.heightPixels;
// int width = displayMetrics.widthPixels;
int height = dip2px(300);
int width = dip2px(224);
Log.d(TAG, "width: " + width + ", height: " + height);
// mSmallHeight = height / 3;
// mSmallWidth = width / 3;
mGLSurfaceViewLocal = new GLSurfaceView(this);
if (mLocalContainer.getChildCount() > 0) {
mLocalContainer.removeAllViews();
}
mLocalContainer.addView(mGLSurfaceViewLocal,
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
mVideoManager = VideoManager.createInstance(this);
mVideoManager.allocate(width, height, 30, io.agora.kit.media.constant.Constant.CAMERA_FACING_FRONT);
mVideoManager.setRenderView(mGLSurfaceViewLocal);
mVideoManager.connectEffectHandler(mEffectHandler);
// mVideoManager.attachToRTCEngine(getWorker().getRtcEngine());
mVideoManager.attachToRTCEngine(mRtcEngine);
mVideoManager.startCapture();
// mRtcEngine.setupLocalVideo(new VideoCanvas(mLocalView, VideoCanvas.RENDER_MODE_HIDDEN, 1001));
}
```
**4.设置渲染的宽高**
**找到****VideoRender****.java文件,在****onDrawFrame****方法里添加以下代码**
```
GLES20.glViewport(0, 0, mViewWidth, mViewHeight); //加上这句
if (mEffectTextureId <= 0) {
mTextureOES.drawFrame(frame.mTextureId, frame.mTexMatrix, mMVP);
} else {
frame.mTextureId = mEffectTextureId;
mFullFrameRectTexture2D.drawFrame(frame.mTextureId, frame.mTexMatrix, mMVP);
}
```
- 一、产品简介
- 1.功能说明
- 2.平台支持
- 3.官方链接
- 二、集成指引
- android集成指引
- 1.概述
- 2.接入说明
- 3.详细步骤
- 4.使用步骤
- 1.腾讯移动直播
- 2.金山云直播
- 3.三体云直播
- 4.阿里云直播
- 5.七牛云直播
- 6.七牛短视频
- 7.Movieous短视频
- 8.即构直播
- 9.腾讯实时音视频
- 10.网易视频云
- 11.即构实时视频
- 12.融云视频通话
- 13.声网视频互动直播
- 14.声网视频通话
- 15.即构新版实时音视频
- 16.不同直播SDK设置基础美颜方式
- 5.新版美狐集成
- iOS集成指引
- 1.申请MH授权Key
- 2.检查SDK资源
- 3.配置工程
- 4.使用MHUI
- 5. 腾讯直播SDK美颜
- 6.TTT 直播SDK美颜
- 7.TTT 实时互动直播
- 8.金山直播SDK 美颜
- 9.七牛直播SDK 美颜
- 10.七牛短视频SDK 美颜
- 11.Movieous短视频
- 12.Zego(即构)直播SDK 美颜
- 13. Zego(即构)实时音视频SDK 美颜
- 14. 网易直播SDK美颜
- 15. 腾讯互动直播SDK美颜
- 16. 腾讯实时音视频
- 17.融云实时音视频
- 18.声网视频通话
- 19.声网直播
- 20. 腾讯短视频录制
- 21.阿里直播 SDK 美颜
- 22.阿里音视频
- 2.4.X版本安卓集成指引
- 1.详细步骤
- 2.云直播平台具体接入
- 1.腾讯移动直播
- 2.阿里云音视频
- 三、MHSDK美颜相关接口部分
- andorid美颜相关接口文档说明
- 美颜相关接口说明文档
- 设置滤镜
- 设置贴纸
- iOS美颜相关接口说明文档
- 1.初始化
- 2.美颜相关接口说明文档
- 3.美颜功能说明
- 四、常见问题
- android常见问题
- 1.认证失败原因
- 2.调用美型、贴纸、特效、哈哈镜没有效果
- 3.MHBeautyManager的特别声明
- 4.使用MHUI的注意事项
- 5.卡顿问题
- 6.闪退问题
- 7. 贴纸无法下载
- 8.andriodX(腾讯云)环境集成问题:
- 9.导入新的sdk出现乱码
- 10.弹出的UI有阴影效果
- 11.安卓10出现获取网络资源失败请检查网络
- 12.美狐可以记录设置的各种参数吗?
- 13.(七牛云)替换sdk画面上下颠倒
- 14.贴纸可以自定义吗
- 15.您这边可以短视频录制吗
- 16.MHSDK必须本地依赖吗
- 17.找不到某个方法
- 18.环信不显示自己的头像框
- 19.如何取消特效
- 20.水印没有找到
- 21.声网视频通话大小屏切换问题
- iOS常见问题
- 1.iOS认证失败原因
- 2.美颜无效果
- 3.贴纸下载失败
- 4.贴纸可下载,无效果
- 5. IPA processing failed/上架打包失败
- 6.存储美颜默认数据
- 7.如果遇到了Failed to create IOSurface image (texture)
- 8.opencv.framework冲突
- 五、联系方式