大班直播

视图布局


添加摄像头预览视图AspectTextureView
    <FrameLayout xmlns:android="http://    schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.talkfun.livepublish.view.AspectTextureView
            android:id="@+id/txv_preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
添加白板视图
    <com.talkfun.whiteboard.view.CloudWhiteBoardView
        android:id="@+id/white_board"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

初始化直播


  • 创建直播逻辑实例
        ILive.LivePresenter mLivePresenterImpl;
        private void initLivePresenter() {
             mLivePresenterImpl = new LivePresenterImpl(mContext,cameraPreview);
             //设置推流事件监听
             mLivePresenterImpl.setStreamerListener(this);
             //设置直播事件监听
             mLivePresenterImpl.setLiveListener(this);
        }
  • 初始化直播模块,如果prepare()返回false,则直播初始化失败不能直播。(prepare()失败一般是获取摄像头或音频录制权限失败引发)
        if (!mLivePresenterImpl.prepare()) {
                finish();
                return;
            }

初始化白板模块


  • 初始化IWhiteBoard.WhiteBoardPresenter对象WhiteBoardPresenterImpl
        IWhiteBoard.WhiteBoardPresenter mWhiteBoardPresenterImpl
        mWhiteBoardPresenterImpl = new WhiteBoardPresenterImpl();
        //设置白板视图对象
        mWhiteBoardPresenterImpl.setWhiteBoardView(view);

文档列表逻辑、聊天逻辑、问答逻辑


  • 初始化文档列表逻辑
        //实例化文档、图片加载逻辑对象
        IDocument.DocumentPresenter presenter;
        presenter = new DocumentPresenterImpl(mContext);
        //加载文档列表数据
        presenter.getDocumentList(new IDocument.GetDocumentListCallback() {
                @Override
                public void onGetDocuments(List<DocDataBean> list) {
                    //获取文档列表回调,如果没文档数据list为空
                    if(list != null){
                        ...
                    }
                }
            });
        //加载本地图片数据
         presenter.getPictureBucketList(new IDocument.GetDevicePictureBucketsCallback() {
                @Override
                public void onGetDevicePictureBuckets(List<DevicePictureBucket> list) {
                      if(list != null){
                        ...
                    }
                }
            });
  • 初始化聊天逻辑
        IChat.ChatPresenter presenter;
        presenter = new ChatPresenterImpl();
  • 初始化问答逻辑
        IQA.QAPresenter mQAPresenterImpl;
        mQAPresenterImpl = new QAPresenterImpl();

载入文档、图片


  • 初始化文件传输对象
    IFileTransfer.Presenter mFileTransfer;
    mFileTransfer = new FileTransferPresenterImpl();
  • 载入文档资源
     mFileTransfer.loadDocRes(docDetailData, new IFileTransfer.LoadDocDataCallback() {
            @Override
            public void onLoadDocDataProgress(String progress) {

            }

            @Override
            public void onLoadDocDataSuccess(DocumentInfoBean data) {

            }

            @Override
            public void onLoadDocDataFail(int code,String msg) {

            }
        });
  • 上传选中图片资源--插入图片
      mFileTransfer.uploadImagesByUri(context,selectImageList, new IFileTransfer.UpdateImageCallback() {
            @Override
            public void onUploadImageProgress(int progress) {

            }

            @Override
            public void onUploadImageFail(String msg) {

            }

            @Override
            public void onUploadImageSuccess(List<UploadDocDataBean> dataList) {

            }
        });

开始直播


  • 开始直播,调用ILiveIn.Presenter.startLive()申请直播
     mLivePresenterImpl.startLive();
  • 开始直播回调
        //开始直播成功回调
    public void onStartLiveSuccess() {
        setIsLiving(true);
        whiteBoardFragment.startSendOperateCommand(this);
        if (mIsStart) {
        showLiveStatusTip(UIUtil.getString(R.string.start_live_success));
        }
    }

     /**
      * 开始直播失败回调
      */
     @Override
     public void onStartLiveFail(String error) {
        ivStartOrStop.setImageResource(R.mipmap.btn_start_live);
        mIsLiving = false;
        mIsStart = false;
          showLiveStatusTip(UIUtil.getString(R.string.start_live_fail));
      }

    /**
     * 推流成功回调
     */
    @Override
    public void onStreamOpenSuccess() {
         Toast.makeText(this, "推流成功", Toast.LENGTH_SHORT).show();
    }

    /**
     * 推流失败回调
     */
    @Override
    public void onStreamOpenFail() {
        Toast.makeText(this, "推流失败", Toast.LENGTH_SHORT).show();
    }

结束直播



    //结束直播
    mLivePresenterImpl.stopLive();

生命周期方法


在Activity的onResume()、onPause()、onDestroy()方法中调用相应方法


     @Override
    protected void onResume() {
        super.onResume();
        mLivePresenterImpl.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mLivePresenterImpl.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLivePresenterImpl.onDestroy();
    }

results matching ""

    No results matching ""