React-native项目集成腾讯云直播

问题描述

我想将腾讯云的直播集成到react-native项目中,然后在startCameraPreview的时候报错了,错误是
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 初始化是可以播放的 ,点击开始的话就不行

clipboard.png

问题出现的环境背景及自己尝试过哪些方法

这个应该就是ui线程的问题,然后我将 mLivePusher.startCameraPreview(mPusherView);写到了ui线程中,然后就是不出预览页 ,也没有进行报错

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
RN 代码

 <TouchableOpacity onPress={() => this.ttt()} style={{ position: 'absolute', left: 200 }}>
                    <Text style={{ color: 'red' }}>开始直播</Text>
 </TouchableOpacity>

 cameraPush.startPush();

ANDROID 代码

modle文件

![图
clipboard.png

videoManager 文件

@Nonnull
@Override
protected LinearLayout createViewInstance(@Nonnull ThemedReactContext reactContext) {
    PushViewManager.mContext = mContext;
    PushViewManager.reactContext = reactContext;
    return PushViewManager.initMainView();
}

PushViewManager 文件,初始化界面的文件

public static LinearLayout initMainView() {
    if (mHandler == null)
        mHandler = new Handler();

    relativeLayout = new LinearLayout(mContext);
    relativeLayout.setBackgroundColor(Color.parseColor(("#fff000")));
    relativeLayout.setMinimumHeight(MATCH_PARENT);
    relativeLayout.setMinimumWidth(MATCH_PARENT);

    mPusherView = new TXCloudVideoView(mContext);
    mPusherView.setBackgroundColor(Color.parseColor("#78c3fb"));
    mPusherView.setMinimumHeight(200);
    mPusherView.setMinimumWidth(200);
    relativeLayout.addView(mPusherView);

// 初始化mLivePusher

    mLivePusher = new TXLivePusher(mContext);
    mLivePushConfig = new TXLivePushConfig();
    mLivePushConfig.setVideoEncodeGop(5);
    mLivePusher.setConfig(mLivePushConfig);

    mPusherView.setVisibility(View.VISIBLE);
    mLivePusher.startCameraPreview(mPusherView);

    return relativeLayout;

}

public static void startPush() {
    mPusherView.layout(0, 0, 1080, 1080);
    mPusherView.setVisibility(View.VISIBLE);
    mLivePusher.startCameraPreview(mPusherView);
}
 public boolean startRTMPPush() {
   startPush(); 
  }

你期待的结果是什么?实际看到的错误信息又是什么?

现在初始化能够出现界面,但是点击开始的时候就不会出,只出了设置的背景色 但是没有出画面!

阅读 5.3k
1 个回答
新手上路,请多包涵

老哥,请问你是怎么在react-native里集成腾讯云直播的?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题