## **1****.騰訊移動直播**
注:以下文檔針對騰訊6.5版本,如果需要適配6.5以上版本詳細看本節結尾說明。
1.初始化MHSDK
**找到LpApplication.java文件,初始化SDK**
MHSDK.getInstance().init(this," ");
2.初始化美顏界面
注意添加自定義渲染的監聽
mLivePusher.setVideoProcessListener(this);
**找到TxMainActivity.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() {
????????beautyContainer = findViewById(R.id.beauty_view_container);
????????mHandler = new Handler(getMainLooper());
????????if (MHSDK.getInstance().isVerEnd()){
????????????setBeautyView();
????????}else {
????????????if (beautyThread != null) {
????????????????beautyThread.interrupt();
????????????????beautyThread = null;
????????????}
????????????beautyThread = new BeautyThread(this);
????????????beautyThread.start();
????????}
????}
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.setCameraClickListener(this);
????????beautyViewHolder.setVisibleListener(visible -> {
????????????if (!visible) {
????????????????beautyViewHolder.show();
????????????}
????????}); ???????
????}
private void initMHBeautyManager(){
????if (mhBeautyManager == null) {
????????mhBeautyManager = new MHBeautyManager(this,true); mhBeautyManager.setBeautyDataModel(BeautyDataModel.getInstance());
if (beautyViewHolder != null) { ????????
beautyViewHolder.setMhBeautyManager(mhBeautyManager);
????????}
????}
}
@Override
protected void onResume() {
????super.onResume();
????initMHBeautyManager();
????Log.d("meihu_beauty", "TxMainActivity--onResume");
}
????static class DiaLogListener implements DialogInterface.OnClickListener {
????????WeakReference activityWeakReference;
????????DiaLogListener(TxMainActivity activity) {
????????????this.activityWeakReference = new WeakReference<>(activity);
????????}
????????@Override
????????public void onClick(DialogInterface dialog, int which) {
????????????TxMainActivity 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(TxMainActivity activity) {
????????????this.activityWeakReference = new WeakReference<>(activity);
????????}
????????@Override
????????public void onClick(DialogInterface dialog, int which) {
????????????TxMainActivity activity = activityWeakReference.get();
????????????if (activity == null)return;
????????????switch (which){
????????????????case -1:
????????????????????activity.retryCount ++;
????????????????????MHSDK.getInstance().clearVerNote();
????????????????????MHSDK.getInstance().verify("");
????????????????????activity.initBeautyView();
????????????????????dialog.cancel();
// ???????????????????System.exit(0);
????????????????????break;
????????????????case -2:
????????????????????dialog.cancel();
????????????????????break;
????????????}
????????}
????}
????//由于demo進入應用直接進入美顏界面,為了防止授權校驗未完成而一直顯示標準版界面,需要等授權校驗完成后初始化對應的美顏界面(延遲1秒或者按下面處理)
????static class BeautyThread extends ?Thread {
????????WeakReference mainActivityWeakReference;
????????BeautyThread(TxMainActivity 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();
????????????????}
????????????}
????????????TxMainActivity activity = mainActivityWeakReference.get();
????????????if (activity != null){
????????????????activity.mHandler.post(activity::setBeautyView);
????????????}
????????}
????}
????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();
????}
@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()****方法**
**在布局文件中添加美顏UI**
```
<RelativeLayout
????android:id="@+id/beauty_view_container"
????android:layout_width="match_parent"
????android:layout_height="wrap_content"
????/>
```
3.自定義渲染
實現TXLivePusher.VideoCustomProcessListener接口,利用livePusher.setVideoProcessListener(this);//設置回調。
```
????@Override
????public int onTextureCustomProcess(int texture, int width, int height) {
????????int textureId = texture;
????????try {
????????????if (mhBeautyManager == null) {
????????????????return textureId;
????????????}
????????????long st = System.currentTimeMillis();
????????????int ?faceScale = 4; //人臉識別對紋理的縮小倍數
????????????int ?textureScale = 2;//圖像渲染對紋理的縮小倍數
????????????if (mDeviceLevel == DEVICE_LEVEL_HIGH) {
????????????????textureScale = 1;
????????????}
????????????int align = 128;
????????????int newWidth = ?((width * 4 + (align - 1)) & ~(align - 1))/4;
????????????int newHeight = ?((height * 4 + (align - 1)) & ~(align - 1))/4;
????????????textureId = mhBeautyManager.render12(texture, newWidth, newHeight,faceScale,textureScale);
????????????long et = System.currentTimeMillis();
// ???????????Log.e(TAG, "onTextureCustomProcess: ---->" + (et - st));
????????} catch (Exception e) {
????????????e.printStackTrace();
????????}
????????return textureId;
????}
@Override
public void onDetectFacePoints(float[] floats) {
}
@Override
public void onTextureDestoryed() {
????if (mhBeautyManager != null) {
????????mhBeautyManager.destroy();
????????mhBeautyManager = null;
????}
}
```
說明:
1.如果出現貼紙資源不能下載的情況, 請在AndroidManifest.xml文件的application節點添加????????android:usesCleartextTraffic="true"屬性。
2.如果使用騰訊SDK6.5(不包含6.5)以上的版本,需要更改紋理的縮小參數,修改方式如下
```
textureId = mhBeautyManager.render12(texture, width, height,faceScale,textureScale);
```
其中第4個參數為人臉識別輸入對紋理的縮小倍數,第5個參數為自定義渲染圖像的縮小倍數。
如:當騰訊SDK返回的紋理大小為1080x1905,第4個參數為4時,人臉識別輸入的紋理大小為原來的1/4, 大小為270x476。第5個參數為2時,自定義渲染的圖像為原來的1/2,即540x952。具體還可以根據卡頓和清晰度情況來設置第4個和第5個參數。
3.?如果使用騰訊SDK6.5(不包含6.5)以上的版本,還可以根據手機性能來實現對紋理的縮小和適配。相關代碼如下:
重寫onTextureCustomProcess方法:
```
?@Override
????public int onTextureCustomProcess(int texture, int width, int height) {
????????int textureId = texture;
????????try {
????????????if (mhBeautyManager == null) {
????????????????return textureId;
????????????}
????????????long st = System.currentTimeMillis();
????????????int ?faceScale = 4; //人臉識別對紋理的縮小倍數
????????????int ?textureScale = 2;//圖像渲染對紋理的縮小倍數
????????????if (mDeviceLevel == DEVICE_LEVEL_HIGH) {
????????????????textureScale = 1;
????????????}
????????????int align = 128;
????????????int newWidth = ?((width * 4 + (align - 1)) & ~(align - 1))/4;
????????????int newHeight = ?((height * 4 + (align - 1)) & ~(align - 1))/4;
????????????textureId = mhBeautyManager.render12(texture, newWidth, newHeight,faceScale,textureScale);
????????????long et = System.currentTimeMillis();
// ???????????Log.e(TAG, "onTextureCustomProcess: ---->" + (et - st));
????????} catch (Exception e) {
????????????e.printStackTrace();
????????}
????????return textureId;
????}
```
- 一、產品簡介
- 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沖突
- 五、聯系方式