自定义了一个MessageContent信息,调用发送该信息,发送失败,错误码-1

aabbcc 8月前 160

以下是自定义的类,IntercomStartMessageContent,调用ChatManager.sendMessage发送该自定义信息,发送失败回调onFailure函数,errorCode码为-1,这个是什么问题导致的?-1代表什么

@ContentTag(type = MessageContentType.ContentType_Call_Intercom_Start, flag = PersistFlag.Persist)
public class IntercomStartMessageContent extends MediaMessageContent {

    private String indexPath;

    public IntercomStartMessageContent() {
        this.mediaType = MessageContentMediaType.INTERCOM;
    }

    public IntercomStartMessageContent(String audioPath) {
        this.indexPath = audioPath;
        this.mediaType = MessageContentMediaType.INTERCOM;
    }

    public String getIndexPath() {
        return indexPath;
    }

    public void setIndexPath(String indexPath) {
        this.indexPath = indexPath;
    }

    @Override
    public MessagePayload encode() {
        MessagePayload payload = super.encode();
        payload.searchableContent = "[语音]";

        try {
            JSONObject objWrite = new JSONObject();
            objWrite.put("indexPath", indexPath);
            payload.content = objWrite.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return payload;
    }

    @Override
    public void decode(MessagePayload payload) {
        super.decode(payload);
        try {
            if (payload.content != null) {
                JSONObject jsonObject = new JSONObject(payload.content);
//                duration = jsonObject.optInt("duration");
                indexPath = jsonObject.optString("indexPath");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String digest(Message message) {
        return "[语音]";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(this.indexPath);
    }

    protected IntercomStartMessageContent(Parcel in) {
        super(in);
        this.indexPath = in.readString();
    }

    public static final Creator<IntercomStartMessageContent> CREATOR = new Creator<IntercomStartMessageContent>() {
        @Override
        public IntercomStartMessageContent createFromParcel(Parcel source) {
            return new IntercomStartMessageContent(source);
        }

        @Override
        public IntercomStartMessageContent[] newArray(int size) {
            return new IntercomStartMessageContent[size];
        }
    };
}
最新回复 (1)
  • x86 8月前
    引用 2

    你好,继承MediaMessageContent时,表示是一种媒体类型消息,可能需要上传媒体数据,要求设置localPath或者remoteUrl字段。

    看了下你的消息内容,继承自MessageContent即可

返回