use of com.easemob.chat.VoiceMessageBody in project wechat by motianhuo.
the class MessageAdapter method handleVoiceMessage.
/**
* 语音消息
*
* @param message
* @param holder
* @param position
* @param convertView
*/
private void handleVoiceMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
VoiceMessageBody voiceBody = (VoiceMessageBody) message.getBody();
holder.tv.setText(voiceBody.getLength() + "\"");
holder.iv.setOnClickListener(new VoicePlayClickListener(message, holder.iv, holder.iv_read_status, this, activity, username));
holder.iv.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.VOICE.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
return true;
}
});
if (((ChatActivity) activity).playMsgId != null && ((ChatActivity) activity).playMsgId.equals(message.getMsgId()) && VoicePlayClickListener.isPlaying) {
AnimationDrawable voiceAnimation;
if (message.direct == EMMessage.Direct.RECEIVE) {
holder.iv.setImageResource(R.anim.voice_from_icon);
} else {
holder.iv.setImageResource(R.anim.voice_to_icon);
}
voiceAnimation = (AnimationDrawable) holder.iv.getDrawable();
voiceAnimation.start();
} else {
if (message.direct == EMMessage.Direct.RECEIVE) {
holder.iv.setImageResource(R.drawable.chatfrom_voice_playing);
} else {
holder.iv.setImageResource(R.drawable.chatto_voice_playing);
}
}
if (message.direct == EMMessage.Direct.RECEIVE) {
if (message.isListened()) {
// 隐藏语音未听标志
holder.iv_read_status.setVisibility(View.INVISIBLE);
} else {
holder.iv_read_status.setVisibility(View.VISIBLE);
}
System.err.println("it is receive msg");
if (message.status == EMMessage.Status.INPROGRESS) {
holder.pb.setVisibility(View.VISIBLE);
System.err.println("!!!! back receive");
((FileMessageBody) message.getBody()).setDownloadCallback(new EMCallBack() {
@Override
public void onSuccess() {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
holder.pb.setVisibility(View.INVISIBLE);
notifyDataSetChanged();
}
});
}
@Override
public void onProgress(int progress, String status) {
}
@Override
public void onError(int code, String message) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
holder.pb.setVisibility(View.INVISIBLE);
}
});
}
});
} else {
holder.pb.setVisibility(View.INVISIBLE);
}
return;
}
// until here, deal with send voice msg
switch(message.status) {
case SUCCESS:
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.GONE);
break;
case FAIL:
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.VISIBLE);
break;
case INPROGRESS:
holder.pb.setVisibility(View.VISIBLE);
holder.staus_iv.setVisibility(View.GONE);
break;
default:
sendMsgInBackground(message, holder);
}
}
use of com.easemob.chat.VoiceMessageBody in project wechat by motianhuo.
the class ChatActivity method sendVoice.
/**
* 发送语音
*
* @param filePath
* @param fileName
* @param length
* @param isResend
*/
private void sendVoice(String filePath, String fileName, String length, boolean isResend) {
if (!(new File(filePath).exists())) {
return;
}
try {
final EMMessage message = EMMessage.createSendMessage(EMMessage.Type.VOICE);
// 如果是群聊,设置chattype,默认是单聊
if (chatType == CHATTYPE_GROUP)
message.setChatType(ChatType.GroupChat);
message.setReceipt(toChatUsername);
int len = Integer.parseInt(length);
VoiceMessageBody body = new VoiceMessageBody(new File(filePath), len);
message.addBody(body);
conversation.addMessage(message);
adapter.refresh();
listView.setSelection(listView.getCount() - 1);
setResult(RESULT_OK);
// send file
// sendVoiceSub(filePath, fileName, message);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations