android发送语音消息给ios,能看到语音消息 已经发送过去了,但是播放不了文件,你们那边能复现? log稍后让ios那边抓下
-
创建时间
15年11月23日
-
最后回复
15年11月25日
-
6
回复
-
1.5K
浏览
-
4
用户
android发送语音消息给ios,能看到语音消息 已经发送过去了,但是播放不了文件,你们那边能复现? log稍后让ios那边抓下
android 发送消息 public void sendAudio(String audioPath) {
try {
AVIMAudioMessage audioMsg = new AVIMAudioMessage(audioPath);
sendMsg(audioMsg, audioPath, sendCallback);
} catch (IOException e) {
LogUtils.logException(e);
}
}
private void sendMsg(final AVIMTypedMessage msg, final String originPath, final SendCallback callback) {
if (!chatManager.isConnect()) {
LogUtils.i("im not connect");
}
//发送消息的回调
conversation.sendMessage(msg, AVIMConversation.RECEIPT_MESSAGE_FLAG, new AVIMConversationCallback() {
@Override
public void done(AVIMException e) {
if (e == null && originPath != null) {
File tmpFile = new File(originPath);
File newFile = new File(PathUtils.getChatFilePath(msg.getMessageId()));
boolean result = tmpFile.renameTo(newFile);
if (!result) {
LogUtils.i("move file failed, can't use local cache");
}
}
if (callback != null) {
if (e != null) {
callback.onError(msg, e);
} else {
callback.onSuccess(msg);
}
}
录音的代码 用的是MediaRecorder
private void startRecording() {
try {
if (recorder == null) {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(outputPath);
recorder.prepare();
} else {
recorder.reset();
recorder.setOutputFile(outputPath);
}
recorder.start();
thread = new ObtainDecibelThread();
thread.start();
recordEventListener.onStartRecord();
} catch (IOException e) {
e.printStackTrace();
}
}