Example #1
0
        /// <summary>
        /// 结束录音并发送语音消息
        /// </summary>
        /// <returns>false表示启动发送失败,true表示启动发送成功</returns>
        public bool StopRecordAndSendAudio()
        {
            if (lastRecordAudioMessage == null)
            {
                return(false);
            }
            var audioMsg = lastRecordAudioMessage;

            if (audioMsg.sendStatus == SendStatus.Fail)
            {
                Log.e("StopRecordAndSendAudio Fail! SendStatus is Fail!");
                lastRecordAudioMessage = null;
                return(false);
            }
            YIMEngine.ErrorCode code = IMAPI.Instance().StopAudioMessage(audioMsg.extraParam);
            lastRecordAudioMessage = null;
            if (code == YIMEngine.ErrorCode.Success)
            {
                return(true);
            }
            else
            {
                Log.e("StopRecordAndSendAudio Fail! code:" + code.ToString());
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 启动录音
        /// </summary>
        /// <param name="reciverID">接收者id,私聊就用用户id,频道聊天就用频道id</param>
        /// <param name="chatType">私聊消息还是频道消息</param>
        /// <param name="extraMsg">附带自定义文本消息内容</param>
        /// <param name="recognizeText">是否开启语音转文字识别功能</param>
        /// <param name="callback">语音消息发送回调通知,会通知多次,通过AudioMessage的sendStatus属性可以判断是哪个状态的回调</param>
        /// <returns></returns>
        public AudioMessage StartRecordAudio(string reciverID, ChatType chatType, string extraMsg, bool recognizeText, Action <StatusCode, AudioMessage> callback)
        {
            ulong reqID = 0;

            YIMEngine.ErrorCode code = 0;
            if (recognizeText)
            {
                code = IMAPI.Instance().SendAudioMessage(reciverID, (YIMEngine.ChatType)chatType, ref reqID);
            }
            else
            {
                code = IMAPI.Instance().SendOnlyAudioMessage(reciverID, (YIMEngine.ChatType)chatType, ref reqID);
            }
            var msg = new AudioMessage(GetCurrentUserID().UserID, reciverID, chatType, extraMsg, false);

            if (code == YIMEngine.ErrorCode.Success)
            {
                msg.requestID          = reqID;
                msg.sendStatus         = SendStatus.NotStartSend;
                lastRecordAudioMessage = msg;
                MessageCallbackObject callbackObj = new MessageCallbackObject(msg, MessageBodyType.Voice, callback);
                IMInternalManager.Instance.AddMessageCallback(reqID, callbackObj);
            }
            else
            {
                msg.sendStatus = SendStatus.Fail;
                Log.e("Start Record Fail! code:" + code.ToString());
                if (callback != null)
                {
                    callback(Conv.ErrorCodeConvert(code), msg);
                }
            }
            return(msg);
        }