我是靠谱客的博主 诚心黑猫,最近开发中收集的这篇文章主要介绍涂鸦ipc摄像头多画面调用关键代码,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

android10,rk平台px30


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.cnd.zhongkong.qiyeban.R;
import com.tuya.smart.android.camera.sdk.TuyaIPCSdk;
import com.tuya.smart.android.camera.sdk.api.ITuyaIPCCore;
import com.tuya.smart.android.camera.sdk.api.ITuyaIPCDoorbell;
import com.tuya.smart.api.service.MicroServiceManager;
import com.tuya.smart.camera.camerasdk.typlayer.callback.AbsP2pCameraListener;
import com.tuya.smart.camera.camerasdk.typlayer.callback.OperationDelegateCallBack;
import com.tuya.smart.camera.ipccamerasdk.p2p.ICameraP2P;
import com.tuya.smart.camera.middleware.p2p.ITuyaSmartCameraP2P;
import com.tuya.smart.camera.middleware.widget.AbsVideoViewCallback;
import com.tuya.smart.camera.middleware.widget.TuyaCameraView;
import com.tuya.smart.commonbiz.bizbundle.family.api.AbsBizBundleFamilyService;
import com.tuya.smart.home.sdk.TuyaHomeSdk;
import com.tuya.smart.home.sdk.bean.HomeBean;
import com.tuya.smart.home.sdk.callback.ITuyaGetHomeListCallback;
import com.tuya.smart.home.sdk.callback.ITuyaHomeResultCallback;

import java.util.List;

/**
 * 单独测试ipc,暂时没有找到在匿名类引用ITuyaSmartCameraP2P 变量的方法
 */
public class ActivityIPCMain extends AppCompatActivity {
    private static final String TAG="ActivityIPCMain:xwg";
    TuyaCameraView mVideoView,mVideoView2,mVideoView3,mVideoView4;  //ipc预览界面
    private ITuyaSmartCameraP2P mCameraP2P,mCameraP2P2,mCameraP2P3,mCameraP2P4;
    private int p2pType;
   private TuyaHomeSdk tuyahomesdk= new TuyaHomeSdk();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_i_p_c_main);
        mVideoView=(TuyaCameraView)findViewById(R.id.camera_video_view);
        mVideoView2=(TuyaCameraView)findViewById(R.id.camera_video_view2);
        mVideoView3=(TuyaCameraView)findViewById(R.id.camera_video_view3);
        mVideoView4=(TuyaCameraView)findViewById(R.id.camera_video_view4);
        initIPC(tuyahomesdk,123,"xxx",mVideoView);
        initIPC2(tuyahomesdk,123,"yyy",mVideoView2);
        initIPC3(tuyahomesdk,123,"zzz",mVideoView3);
        initIPC4(tuyahomesdk,123,"aaa",mVideoView4);
    }
//ipc1
    private void initIPC(TuyaHomeSdk tuyaHomeSdk,
                        long homeId,
                        String devId,
                        TuyaCameraView tuyaCameraView
                        ){
        tuyaHomeSdk.getHomeManagerInstance().queryHomeList(new ITuyaGetHomeListCallback() {
            @Override
            public void onSuccess(List<HomeBean> homeBeans) {

                AbsBizBundleFamilyService serviceAbs=MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleFamilyService.class.getName());
                serviceAbs.setCurrentHomeId(homeId);
                tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail(new ITuyaHomeResultCallback() {
                    @Override
                    public void onSuccess(HomeBean bean) {

                        ITuyaIPCCore cameraInstance = TuyaIPCSdk.getCameraInstance();
                        Log.i(TAG,devId+" is ipc:"+cameraInstance.isIPCDevice(devId));
                        if (cameraInstance != null){
                            mCameraP2P = cameraInstance.createCameraP2P(devId); //创建对象
                            int p2pType = cameraInstance.getP2PType(devId);
                        }
                        else
                            Log.i(TAG,"cameraInstance is null");
//                        tuyaCameraView=(TuyaCameraView)findViewById(tuyaCameraViewID);
                        tuyaCameraView.setViewCallback(new AbsVideoViewCallback() {
                            @Override
                            public void onCreated(Object view) {
                                super.onCreated(view);
                                if(mCameraP2P!=null){
                                    mCameraP2P.generateCameraView(view);
                                    if(!mCameraP2P.isConnecting()){
                                        Log.i(TAG,"p2p not isConnecting");
                                        if (cameraInstance != null && cameraInstance.isLowPowerDevice(devId)) {
                                            ITuyaIPCDoorbell doorbell = TuyaIPCSdk.getDoorbell();
                                            if (doorbell != null) {
                                                doorbell.wirelessWake(devId);
                                            }
                                        }
                                        mCameraP2P.connect(devId, new OperationDelegateCallBack() {
                                            @Override
                                            public void onSuccess(int i, int i1, String s) {
//                                                开始预览
                                                mCameraP2P.startPreview(ICameraP2P.HD, new OperationDelegateCallBack() {
                                                    @Override
                                                    public void onSuccess(int sessionId, int requestId, String data) {
                                                        Log.d(TAG, "start preview onSuccess");
//                                                                isPlay = true;
                                                    }

                                                    @Override
                                                    public void onFailure(int sessionId, int requestId, int errCode) {
                                                        Log.d(TAG, "start preview onFailure, errCode: " + errCode);
//                                                                isPlay = false;
                                                    }
                                                });
                                            }

                                            @Override
                                            public void onFailure(int i, int i1, int i2) {
                                                Log.i(TAG,"mCameraP2P.connect onFailure");
                                            }
                                        });
                                    }
                                    else
                                        Log.i(TAG,"isConnecting");
                                }
                                else
                                    Log.i(TAG,"mCameraP2P=null");
                            }
                        });//mVideoView.setViewCallback
                        tuyaCameraView.createVideoView(p2pType);
                        if(mCameraP2P!=null){
                            mCameraP2P.registerP2PCameraListener(new AbsP2pCameraListener() {
                                @Override
                                public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
                                    super.onSessionStatusChanged(camera, sessionId, sessionStatus);
                                }
                            });
                        }
                        else Log.i(TAG,"mCameraP2P=null");
                    }

                    @Override
                    public void onError(String errorCode, String errorMsg) {
                        Log.i(TAG,"tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail error:"+errorCode+",errorMsg:"+errorMsg);
                    }
                });//tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail
            }

            @Override
            public void onError(String errorCode, String error) {
                Log.i(TAG,"tuyaHomeSdk.getHomeManagerInstance().queryHomeList errorCde:"+errorCode+",error:"+error);
            }
        });
    }
//    ipc2
    private void initIPC2(TuyaHomeSdk tuyaHomeSdk,
                         long homeId,
                         String devId,
                         TuyaCameraView tuyaCameraView
    ){
        tuyaHomeSdk.getHomeManagerInstance().queryHomeList(new ITuyaGetHomeListCallback() {
            @Override
            public void onSuccess(List<HomeBean> homeBeans) {

                AbsBizBundleFamilyService serviceAbs=MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleFamilyService.class.getName());
                serviceAbs.setCurrentHomeId(homeId);
                tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail(new ITuyaHomeResultCallback() {
                    @Override
                    public void onSuccess(HomeBean bean) {

                        ITuyaIPCCore cameraInstance = TuyaIPCSdk.getCameraInstance();
                        Log.i(TAG,devId+" is ipc:"+cameraInstance.isIPCDevice(devId));
                        if (cameraInstance != null){
                            mCameraP2P2 = cameraInstance.createCameraP2P(devId); //创建对象
                            int p2pType = cameraInstance.getP2PType(devId);
                        }
                        else
                            Log.i(TAG,"cameraInstance is null");
//                        tuyaCameraView=(TuyaCameraView)findViewById(tuyaCameraViewID);
                        tuyaCameraView.setViewCallback(new AbsVideoViewCallback() {
                            @Override
                            public void onCreated(Object view) {
                                super.onCreated(view);
                                if(mCameraP2P2!=null){
                                    mCameraP2P2.generateCameraView(view);
                                    if(!mCameraP2P2.isConnecting()){
                                        Log.i(TAG,"p2p not isConnecting");
                                        if (cameraInstance != null && cameraInstance.isLowPowerDevice(devId)) {
                                            ITuyaIPCDoorbell doorbell = TuyaIPCSdk.getDoorbell();
                                            if (doorbell != null) {
                                                doorbell.wirelessWake(devId);
                                            }
                                        }
                                        mCameraP2P2.connect(devId, new OperationDelegateCallBack() {
                                            @Override
                                            public void onSuccess(int i, int i1, String s) {
//                                                开始预览
                                                mCameraP2P2.startPreview(ICameraP2P.HD, new OperationDelegateCallBack() {
                                                    @Override
                                                    public void onSuccess(int sessionId, int requestId, String data) {
                                                        Log.d(TAG, "start preview onSuccess");
//                                                                isPlay = true;
                                                    }

                                                    @Override
                                                    public void onFailure(int sessionId, int requestId, int errCode) {
                                                        Log.d(TAG, "start preview onFailure, errCode: " + errCode);
//                                                                isPlay = false;
                                                    }
                                                });
                                            }

                                            @Override
                                            public void onFailure(int i, int i1, int i2) {
                                                Log.i(TAG,"mCameraP2P.connect onFailure");
                                            }
                                        });
                                    }
                                    else
                                        Log.i(TAG,"isConnecting");
                                }
                                else
                                    Log.i(TAG,"mCameraP2P=null");
                            }
                        });//mVideoView.setViewCallback
                        tuyaCameraView.createVideoView(p2pType);
                        if(mCameraP2P2!=null){
                            mCameraP2P2.registerP2PCameraListener(new AbsP2pCameraListener() {
                                @Override
                                public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
                                    super.onSessionStatusChanged(camera, sessionId, sessionStatus);
                                }
                            });
                        }
                        else Log.i(TAG,"mCameraP2P=null");
                    }

                    @Override
                    public void onError(String errorCode, String errorMsg) {
                        Log.i(TAG,"tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail error:"+errorCode+",errorMsg:"+errorMsg);
                    }
                });//tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail
            }

            @Override
            public void onError(String errorCode, String error) {
                Log.i(TAG,"tuyaHomeSdk.getHomeManagerInstance().queryHomeList errorCde:"+errorCode+",error:"+error);
            }
        });
    }
//ipc3
private void initIPC3(TuyaHomeSdk tuyaHomeSdk,
                     long homeId,
                     String devId,
                     TuyaCameraView tuyaCameraView
){
    tuyaHomeSdk.getHomeManagerInstance().queryHomeList(new ITuyaGetHomeListCallback() {
        @Override
        public void onSuccess(List<HomeBean> homeBeans) {

            AbsBizBundleFamilyService serviceAbs=MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleFamilyService.class.getName());
            serviceAbs.setCurrentHomeId(homeId);
            tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail(new ITuyaHomeResultCallback() {
                @Override
                public void onSuccess(HomeBean bean) {

                    ITuyaIPCCore cameraInstance = TuyaIPCSdk.getCameraInstance();
                    Log.i(TAG,devId+" is ipc:"+cameraInstance.isIPCDevice(devId));
                    if (cameraInstance != null){
                        mCameraP2P3 = cameraInstance.createCameraP2P(devId); //创建对象
                        int p2pType = cameraInstance.getP2PType(devId);
                    }
                    else
                        Log.i(TAG,"cameraInstance is null");
//                        tuyaCameraView=(TuyaCameraView)findViewById(tuyaCameraViewID);
                    tuyaCameraView.setViewCallback(new AbsVideoViewCallback() {
                        @Override
                        public void onCreated(Object view) {
                            super.onCreated(view);
                            if(mCameraP2P3!=null){
                                mCameraP2P3.generateCameraView(view);
                                if(!mCameraP2P3.isConnecting()){
                                    Log.i(TAG,"p2p not isConnecting");
                                    if (cameraInstance != null && cameraInstance.isLowPowerDevice(devId)) {
                                        ITuyaIPCDoorbell doorbell = TuyaIPCSdk.getDoorbell();
                                        if (doorbell != null) {
                                            doorbell.wirelessWake(devId);
                                        }
                                    }
                                    mCameraP2P3.connect(devId, new OperationDelegateCallBack() {
                                        @Override
                                        public void onSuccess(int i, int i1, String s) {
//                                                开始预览
                                            mCameraP2P3.startPreview(ICameraP2P.HD, new OperationDelegateCallBack() {
                                                @Override
                                                public void onSuccess(int sessionId, int requestId, String data) {
                                                    Log.d(TAG, "start preview onSuccess");
//                                                                isPlay = true;
                                                }

                                                @Override
                                                public void onFailure(int sessionId, int requestId, int errCode) {
                                                    Log.d(TAG, "start preview onFailure, errCode: " + errCode);
//                                                                isPlay = false;
                                                }
                                            });
                                        }

                                        @Override
                                        public void onFailure(int i, int i1, int i2) {
                                            Log.i(TAG,"mCameraP2P.connect onFailure");
                                        }
                                    });
                                }
                                else
                                    Log.i(TAG,"isConnecting");
                            }
                            else
                                Log.i(TAG,"mCameraP2P=null");
                        }
                    });//mVideoView.setViewCallback
                    tuyaCameraView.createVideoView(p2pType);
                    if(mCameraP2P3!=null){
                        mCameraP2P3.registerP2PCameraListener(new AbsP2pCameraListener() {
                            @Override
                            public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
                                super.onSessionStatusChanged(camera, sessionId, sessionStatus);
                            }
                        });
                    }
                    else Log.i(TAG,"mCameraP2P=null");
                }

                @Override
                public void onError(String errorCode, String errorMsg) {
                    Log.i(TAG,"tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail error:"+errorCode+",errorMsg:"+errorMsg);
                }
            });//tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail
        }

        @Override
        public void onError(String errorCode, String error) {
            Log.i(TAG,"tuyaHomeSdk.getHomeManagerInstance().queryHomeList errorCde:"+errorCode+",error:"+error);
        }
    });
}

//ipc4
private void initIPC4(TuyaHomeSdk tuyaHomeSdk,
                     long homeId,
                     String devId,
                     TuyaCameraView tuyaCameraView
){
    tuyaHomeSdk.getHomeManagerInstance().queryHomeList(new ITuyaGetHomeListCallback() {
        @Override
        public void onSuccess(List<HomeBean> homeBeans) {

            AbsBizBundleFamilyService serviceAbs=MicroServiceManager.getInstance().findServiceByInterface(AbsBizBundleFamilyService.class.getName());
            serviceAbs.setCurrentHomeId(homeId);
            tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail(new ITuyaHomeResultCallback() {
                @Override
                public void onSuccess(HomeBean bean) {

                    ITuyaIPCCore cameraInstance = TuyaIPCSdk.getCameraInstance();
                    Log.i(TAG,devId+" is ipc:"+cameraInstance.isIPCDevice(devId));
                    if (cameraInstance != null){
                        mCameraP2P4 = cameraInstance.createCameraP2P(devId); //创建对象
                        int p2pType = cameraInstance.getP2PType(devId);
                    }
                    else
                        Log.i(TAG,"cameraInstance is null");
//                        tuyaCameraView=(TuyaCameraView)findViewById(tuyaCameraViewID);
                    tuyaCameraView.setViewCallback(new AbsVideoViewCallback() {
                        @Override
                        public void onCreated(Object view) {
                            super.onCreated(view);
                            if(mCameraP2P4!=null){
                                mCameraP2P4.generateCameraView(view);
                                if(!mCameraP2P4.isConnecting()){
                                    Log.i(TAG,"p2p not isConnecting");
                                    if (cameraInstance != null && cameraInstance.isLowPowerDevice(devId)) {
                                        ITuyaIPCDoorbell doorbell = TuyaIPCSdk.getDoorbell();
                                        if (doorbell != null) {
                                            doorbell.wirelessWake(devId);
                                        }
                                    }
                                    mCameraP2P4.connect(devId, new OperationDelegateCallBack() {
                                        @Override
                                        public void onSuccess(int i, int i1, String s) {
//                                                开始预览
                                            mCameraP2P4.startPreview(ICameraP2P.HD, new OperationDelegateCallBack() {
                                                @Override
                                                public void onSuccess(int sessionId, int requestId, String data) {
                                                    Log.d(TAG, "start preview onSuccess");
//                                                                isPlay = true;
                                                }

                                                @Override
                                                public void onFailure(int sessionId, int requestId, int errCode) {
                                                    Log.d(TAG, "start preview onFailure, errCode: " + errCode);
//                                                                isPlay = false;
                                                }
                                            });
                                        }

                                        @Override
                                        public void onFailure(int i, int i1, int i2) {
                                            Log.i(TAG,"mCameraP2P.connect onFailure");
                                        }
                                    });
                                }
                                else
                                    Log.i(TAG,"isConnecting");
                            }
                            else
                                Log.i(TAG,"mCameraP2P=null");
                        }
                    });//mVideoView.setViewCallback
                    tuyaCameraView.createVideoView(p2pType);
                    if(mCameraP2P4!=null){
                        mCameraP2P4.registerP2PCameraListener(new AbsP2pCameraListener() {
                            @Override
                            public void onSessionStatusChanged(Object camera, int sessionId, int sessionStatus) {
                                super.onSessionStatusChanged(camera, sessionId, sessionStatus);
                            }
                        });
                    }
                    else Log.i(TAG,"mCameraP2P=null");
                }

                @Override
                public void onError(String errorCode, String errorMsg) {
                    Log.i(TAG,"tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail error:"+errorCode+",errorMsg:"+errorMsg);
                }
            });//tuyaHomeSdk.newHomeInstance(homeId).getHomeDetail
        }

        @Override
        public void onError(String errorCode, String error) {
            Log.i(TAG,"tuyaHomeSdk.getHomeManagerInstance().queryHomeList errorCde:"+errorCode+",error:"+error);
        }
    });
}
}

效果图

最后

以上就是诚心黑猫为你收集整理的涂鸦ipc摄像头多画面调用关键代码的全部内容,希望文章能够帮你解决涂鸦ipc摄像头多画面调用关键代码所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部