Skip to content

Restream

chriszeng87 edited this page May 25, 2017 · 6 revisions

SDK本身不会自动重连。在连接失败或连接中断时,可以在收到对应的错误回调时进行重连。
重连的策略可以自定义。

重连

发生编码错误或网络发送错误时,SDK内部会主动停止推流,错误类型包含如下:
KSY_STREAMER_ERROR_CONNECT_BREAKED
KSY_STREAMER_ERROR_DNS_PARSE_FAILED
KSY_STREAMER_ERROR_CONNECT_FAILED
KSY_STREAMER_ERROR_PUBLISH_FAILED
KSY_STREAMER_ERROR_AV_ASYNC
KSY_STREAMER_VIDEO_ENCODER_ERROR_UNSUPPORTED
KSY_STREAMER_AUDIO_ENCODER_ERROR_UNSUPPORTED
KSY_STREAMER_VIDEO_ENCODER_ERROR_UNKNOWN
KSY_STREAMER_AUDIO_ENCODER_ERROR_UNKNOWN

其它错误SDK内部不会主动停止推流,需要开发者根据情况自行处理

错误类型详细说明参考状态和错误回调

代码示例(v4.xDemo中CameraActivity的mOnErrorListener):

            switch (what) {
                case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_UNKNOWN:
                case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_START_FAILED:
                case StreamerConstants.KSY_STREAMER_AUDIO_RECORDER_ERROR_START_FAILED:
                case StreamerConstants.KSY_STREAMER_AUDIO_RECORDER_ERROR_UNKNOWN:
                    break;
                case StreamerConstants.KSY_STREAMER_CAMERA_ERROR_SERVER_DIED:
                    mStreamer.stopCameraPreview();
                    mMainHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            startCameraPreviewWithPermCheck();
                        }
                    }, 5000);
                    break;
               //重连
                default:
                    stopStream();
                    mMainHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            startStream();
                        }
                    }, 3000);
                    break;
            }
Clone this wiki locally