Skip to content

Info&Error_Listener

zanxiaofei edited this page Jul 25, 2017 · 2 revisions

短视频状态和错误回调说明

1. 短视频录制过程消息回调

KSYRecordKit类中提供以下两种回调接口,

  • OnInfoListener 录制过程中状态变更事件回调,状态码为正数。
  • OnErrorListener 录制过程中错误事件回调,事件触发时,录制停止,状态码为负数

接口延用KSYStreamer中的定义,状态码定义在推流库的StreamerConstants中
示例代码参考(RecordActiviy中mOnInfoListener和mOnErrorListener)

1.1 状态码表

名称 数值 含义 msg1
KSY_STREAMER_CAMERA_INIT_DONE 1000 初始化完毕 N/A
KSY_STREAMER_OPEN_FILE_SUCCESS 1 录制成功开始 N/A
KSY_STREAMER_FILE_RECORD_STOPPED 2 录制停止回调,下一次录制开始需要在收到该回调后再进行 N/A

1.2 错误码表

名称 数值 含义 msg1
KSY_STREAMER_ERROR_AV_ASYNC -2004 音视频采集pts差值超过5s 音视频采集pts具体差值,单位ms
KSY_STREAMER_VIDEO_ENCODER_ERROR_UNSUPPORTED -1004 编码器初始化失败 N/A
KSY_STREAMER_VIDEO_ENCODER_ERROR_UNKNOWN -1003 视频编码失败 N/A
KSY_STREAMER_AUDIO_ENCODER_ERROR_UNSUPPORTED -1008 音频初始化失败 N/A
KSY_STREAMER_AUDIO_ENCODER_ERROR_UNKNOWN -1011 音频编码失败 N/A
KSY_STREAMER_CAMERA_ERROR_UNKNOWN -2001 摄像头未知错误 N/A
KSY_STREAMER_CAMERA_ERROR_START_FAILED -2002 打开摄像头失败 N/A
KSY_STREAMER_CAMERA_ERROR_SERVER_DIED -2006 系统Camera服务进程退出 N/A
KSY_STREAMER_AUDIO_RECORDER_ERROR_START_FAILED -2003 录音开启失败 N/A
KSY_STREAMER_AUDIO_RECORDER_ERROR_UNKNOWN -2005 录音开启未知错误 N/A
KSY_STREAMER_CAMERA_ERROR_EVICTED -2007 Camera服务异常退出 N/A
KSY_STREAMER_FILE_PUBLISHER_ERROR_UNKNOWN -4000 文件录制未知错误 N/A
KSY_STREAMER_FILE_PUBLISHER_OPEN_FAILED -4001 文件录制生成文件失败 N/A
KSY_STREAMER_FILE_PUBLISHER_WRITE_FAILED -4002 文件录制写文件失败 N/A
KSY_STREAMER_FILE_PUBLISHER_CLOSE_FAILED -4003 文件录制关闭失败 N/A
KSY_STREAMER_FILE_PUBLISHER_FORMAT_NOT_SUPPORTED -4004 文件录制,文件格式不支持 N/A

2. 编辑合成上传消息回调

KSYEditKit类中提供以下两种回调接口

  • OnInfoListener 编辑合成过程中状态变更事件回调,状态码为正数
  • OnErrorListener 编辑合成过程中错误事件回调,状态码为负数

2.1 状态码表

名称 数值 含义 msgs
SHORTVIDEO_COMPOSE_START 1 合成开始 N/A
SHORTVIDEO_COMPOSE_FINISHED 2 合成结束 msg[0] 合成后文件路径,一般为合成时传入的文件路径
SHORTVIDEO_GET_KS3AUTH 3 KS3鉴权 msg[0]~msg[5] 获取KS3的鉴权Token必要信息,由KS3Client生成

示例代码

  private KSYEditKit.OnInfoListener mOnInfoListener = new KSYEditKit.OnInfoListener() {
        @Override
        public Object onInfo(int type, String... msgs) {
            if (type == ShortVideoConstants.SHORTVIDEO_COMPOSE_START) {
                Log.d(TAG, "compose start");
                //停止编辑预览
                stopEditPreview();
                mBeautySpinner.setSelection(0);
                if (mComposeAlertDialog != null) {
                    mComposeAlertDialog.setCancelable(false);
                    mComposeAlertDialog.show();
                    //开始显示合成过程进度条
                    mComposeAlertDialog.composeStarted();
                }
                return null;
            } else if (type == ShortVideoConstants.SHORTVIDEO_COMPOSE_FINISHED) {
                Log.d(TAG, "compose finished");
                if (mComposeAlertDialog != null) {
                    //关闭合成过程进度条,开启合成文件预览,msg[0]为合成后文件本地路径
                    mComposeAlertDialog.composeFinished(msgs[0]);
                    mComposeFinished = true;
                }
                // 向SDK返回上传必须的信息,以触发文件上传,返回null时不会触发文件上传
                //"ksvsdemo"为bucketInfo,从KS3云服务申请
                //mCurObjectKey:上传文件名(可添加子目录)
                //mPutObjectResponseHandler:上传过程回调
                mCurObjectKey = getPackageName() + "/" + System.currentTimeMillis() + ".mp4";
                KS3ClientWrap.KS3UploadInfo bucketInfo = new KS3ClientWrap.KS3UploadInfo
                        ("ksvsdemo", mCurObjectKey, mPutObjectResponseHandler);
                return bucketInfo;
            } else if (type == ShortVideoConstants.SHORTVIDEO_GET_KS3AUTH) {
                //SDK返回获取KS3鉴权Token必要的信息
                if (msgs.length == 6) {
                    if (mTokenTask == null) {
                        mTokenTask = new KS3TokenTask(getApplicationContext());
                    }
                    //同步向AppServer请求KS3鉴权Token,返回null上传失败
                    return mTokenTask.requsetTokenToAppServer(msgs[0], msgs[1],
                            msgs[2], msgs[3], msgs[4], msgs[5]);
                } else {
                    return null;
                }
            }
            return null;
        }

2.1 错误码表

名称 数值 含义 msgs
SHORTVIDEO_ERROR_SDK_AUTHFAILED -1 SDK鉴权失败,无法合成 N/A
SHORTVIDEO_ERROR_UPLOAD_PARAMS_ERROR -2 App传入上传参数错误,无法上传 N/A
SHORTVIDEO_ERROR_UPLOAD_KS3_TOKEN_ERROR -3 KS3鉴权失败,上传失败 N/A
SHORTVIDEO_ERROR_COMPOSE_FAILED_UNKNOWN -4000 文件合成未知错误 N/A
SHORTVIDEO_ERROR_COMPOSE_FILE_OPEN_FAILED -4001 文件合成生成文件失败 N/A
SHORTVIDEO_ERROR_COMPOSE_FILE_WRITE_FAILED -4002 文件合成写文件失败 N/A
SHORTVIDEO_ERROR_COMPOSE_FILE_CLOSE_FAILED -4003 文件合成文件关闭失败 N/A
SHORTVIDEO_ERROR_COMPOSE_FILE_FORMAT_NOT_SUPPORTED -4004 文件合成,文件格式不支持 N/A

示例代码

 private KSYEditKit.OnErrorListener mOnErrorListener = new KSYEditKit.OnErrorListener() {
        @Override
        public void onError(int type, long msg) {
            switch (type) {
                case ShortVideoConstants.SHORTVIDEO_ERROR_COMPOSE_FAILED_UNKNOWN:
                case ShortVideoConstants.SHORTVIDEO_ERROR_COMPOSE_FILE_CLOSE_FAILED:
                case ShortVideoConstants.SHORTVIDEO_ERROR_COMPOSE_FILE_FORMAT_NOT_SUPPORTED:
                case ShortVideoConstants.SHORTVIDEO_ERROR_COMPOSE_FILE_OPEN_FAILED:
                case ShortVideoConstants.SHORTVIDEO_ERROR_COMPOSE_FILE_WRITE_FAILED:
                    Log.d(TAG, "compose failed:" + type);
                    Toast.makeText(EditActivity.this,
                            "Compose Failed:" + type, Toast.LENGTH_LONG).show();
                    if (mComposeAlertDialog != null) {
                        mComposeAlertDialog.closeDialog();
                        EditActivity.this.startEditPreview();
                    }
                    break;
                case ShortVideoConstants.SHORTVIDEO_ERROR_SDK_AUTHFAILED:
                    Log.d(TAG, "sdk auth failed:" + type);
                    Toast.makeText(EditActivity.this,
                            "Auth failed can't start compose:" + type, Toast.LENGTH_LONG).show();
                    break;
                case ShortVideoConstants.SHORTVIDEO_ERROR_UPLOAD_KS3_TOKEN_ERROR:
                    Log.d(TAG, "ks3 upload token error, upload to ks3 failed");
                    Toast.makeText(EditActivity.this,
                            "Auth failed can't start upload:" + type, Toast.LENGTH_LONG).show();
                    break;


            }
        }
    };

3. 文件上传消息回调

KS3Client提供PutObjectResponseHandler回调接口,返回上传过程中信息
示例代码

private PutObjectResponseHandler mPutObjectResponseHandler = new PutObjectResponseHandler() {
        @Override
        public void onTaskFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
            //上传失败
            Log.e(TAG, "onTaskFailure:" + statesCode);
            if (mComposeAlertDialog != null) {
                mComposeAlertDialog.uploadFinished(false);
            }
        }

        @Override
        public void onTaskSuccess(int statesCode, Header[] responceHeaders) {
            //上传成功,开始获取上传后文件路径
            Log.d(TAG, "onTaskSuccess:" + statesCode);
            if (mComposeAlertDialog != null) {
                mComposeAlertDialog.uploadFinished(true);
            }
        }

        @Override
        public void onTaskStart() {
            Log.d(TAG, "onTaskStart");
            //上传成功,开始显示上传过程进度条
            if (mComposeAlertDialog != null) {
                mComposeAlertDialog.uploadStarted();
            }
        }

        @Override
        public void onTaskFinish() {
            Log.d(TAG, "onTaskFinish");
        }

        @Override
        public void onTaskCancel() {
            Log.d(TAG, "onTaskCancel");
        }

        @Override
        public void onTaskProgress(double progress) {
            //上传进度回调,更新上传进度
            if (mComposeAlertDialog != null) {
                mComposeAlertDialog.uploadProgress(progress);
            }
        }
    };
Clone this wiki locally
You can’t perform that action at this time.