com.hyphenate.chat.EMMessage.ChatType Java Examples
The following examples show how to use
com.hyphenate.chat.EMMessage.ChatType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EaseChatFragment.java From Social with Apache License 2.0 | 6 votes |
protected void sendMessage(EMMessage message){ if (message == null) { return; } if(chatFragmentListener != null){ //设置扩展属性 chatFragmentListener.onSetMessageAttributes(message); } // 如果是群聊,设置chattype,默认是单聊 if (chatType == EaseConstant.CHATTYPE_GROUP){ message.setChatType(ChatType.GroupChat); }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){ message.setChatType(ChatType.ChatRoom); } //发送消息 EMClient.getInstance().chatManager().sendMessage(message); //刷新ui if(isMessageListInited) { messageList.refreshSelectLast(); } }
Example #2
Source File: EaseChatRowImage.java From Social with Apache License 2.0 | 6 votes |
@Override protected void onBubbleClick() { Intent intent = new Intent(context, EaseShowBigImageActivity.class); File file = new File(imgBody.getLocalUrl()); if (file.exists()) { Uri uri = Uri.fromFile(file); intent.putExtra("uri", uri); } else { // The local full size pic does not exist yet. // ShowBigImage needs to download it from the server // first intent.putExtra("secret", imgBody.getSecret()); intent.putExtra("remotepath", imgBody.getRemoteUrl()); intent.putExtra("localUrl", imgBody.getLocalUrl()); } if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) { try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } } context.startActivity(intent); }
Example #3
Source File: EaseChatRowFile.java From Social with Apache License 2.0 | 6 votes |
@Override protected void onBubbleClick() { String filePath = fileMessageBody.getLocalUrl(); File file = new File(filePath); if (file != null && file.exists()) { // 文件存在,直接打开 FileUtils.openFile(file, (Activity) context); } else { // 下载 context.startActivity(new Intent(context, EaseShowNormalFileActivity.class).putExtra("msgbody", message.getBody())); } if (message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) { try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Example #4
Source File: EaseChatFragment.java From nono-android with GNU General Public License v3.0 | 6 votes |
protected void sendMessage(EMMessage message){ if(chatFragmentListener != null){ //设置扩展属性 chatFragmentListener.onSetMessageAttributes(message); } // 如果是群聊,设置chattype,默认是单聊 if (chatType == EaseConstant.CHATTYPE_GROUP){ message.setChatType(ChatType.GroupChat); }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){ message.setChatType(ChatType.ChatRoom); } //发送消息 EMClient.getInstance().chatManager().sendMessage(message); //刷新ui if(isMessageListInited) { messageList.refreshSelectLast(); } }
Example #5
Source File: EaseChatFragment.java From nono-android with GNU General Public License v3.0 | 6 votes |
@Override public void onMessageReceived(List<EMMessage> messages) { for (EMMessage message : messages) { String username = null; // 群组消息 if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) { username = message.getTo(); } else { // 单聊消息 username = message.getFrom(); } // 如果是当前会话的消息,刷新聊天页面 if (username.equals(toChatUsername)) { messageList.refreshSelectLast(); // 声音和震动提示有新消息 EaseUI.getInstance().getNotifier().viberateAndPlayTone(message); } else { // 如果消息不是和当前聊天ID的消息 EaseUI.getInstance().getNotifier().onNewMsg(message); } } }
Example #6
Source File: EaseChatRowVideo.java From Social with Apache License 2.0 | 6 votes |
@Override protected void onBubbleClick() { EMVideoMessageBody videoBody = (EMVideoMessageBody) message.getBody(); EMLog.d(TAG, "video view is on click"); Intent intent = new Intent(context, EaseShowVideoActivity.class); intent.putExtra("localpath", videoBody.getLocalUrl()); intent.putExtra("secret", videoBody.getSecret()); intent.putExtra("remotepath", videoBody.getRemoteUrl()); if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) { try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } } activity.startActivity(intent); }
Example #7
Source File: EaseChatRowVideo.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@Override protected void onBubbleClick() { EMVideoMessageBody videoBody = (EMVideoMessageBody) message.getBody(); EMLog.d(TAG, "video view is on click"); Intent intent = new Intent(context, EaseShowVideoActivity.class); intent.putExtra("localpath", videoBody.getLocalUrl()); intent.putExtra("secret", videoBody.getSecret()); intent.putExtra("remotepath", videoBody.getRemoteUrl()); if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) { try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } } activity.startActivity(intent); }
Example #8
Source File: EaseChatFragment.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@Override public void onMessageReceived(List<EMMessage> messages) { for (EMMessage message : messages) { String username = null; // group message if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) { username = message.getTo(); } else { // single chat message username = message.getFrom(); } // if the message is for current conversation if (username.equals(toChatUsername) || message.getTo().equals(toChatUsername)) { messageList.refreshSelectLast(); EaseUI.getInstance().getNotifier().vibrateAndPlayTone(message); } else { EaseUI.getInstance().getNotifier().onNewMsg(message); } } }
Example #9
Source File: EaseChatFragment.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
protected void sendMessage(EMMessage message){ if (message == null) { return; } if(chatFragmentHelper != null){ //set extension chatFragmentHelper.onSetMessageAttributes(message); } if (chatType == EaseConstant.CHATTYPE_GROUP){ message.setChatType(ChatType.GroupChat); }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){ message.setChatType(ChatType.ChatRoom); } //send message EMClient.getInstance().chatManager().sendMessage(message); //refresh ui if(isMessageListInited) { messageList.refreshSelectLast(); } }
Example #10
Source File: EaseChatFragment.java From Social with Apache License 2.0 | 6 votes |
@Override public void onMessageReceived(List<EMMessage> messages) { for (EMMessage message : messages) { String username = null; // 群组消息 if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) { username = message.getTo(); } else { // 单聊消息 username = message.getFrom(); } // 如果是当前会话的消息,刷新聊天页面 if (username.equals(toChatUsername)) { messageList.refreshSelectLast(); // 声音和震动提示有新消息 EaseUI.getInstance().getNotifier().viberateAndPlayTone(message); } else { // 如果消息不是和当前聊天ID的消息 EaseUI.getInstance().getNotifier().onNewMsg(message); } } }
Example #11
Source File: EaseChatRowImage.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@Override protected void onBubbleClick() { Intent intent = new Intent(context, EaseShowBigImageActivity.class); File file = new File(imgBody.getLocalUrl()); if (file.exists()) { Uri uri = Uri.fromFile(file); intent.putExtra("uri", uri); } else { // The local full size pic does not exist yet. // ShowBigImage needs to download it from the server // first String msgId = message.getMsgId(); intent.putExtra("messageId", msgId); intent.putExtra("localUrl", imgBody.getLocalUrl()); } if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) { try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } } context.startActivity(intent); }
Example #12
Source File: EaseChatRowFile.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
@Override protected void onBubbleClick() { String filePath = fileMessageBody.getLocalUrl(); File file = new File(filePath); if (file.exists()) { // open files if it exist FileUtils.openFile(file, (Activity) context); } else { // download the file context.startActivity(new Intent(context, EaseShowNormalFileActivity.class).putExtra("msgbody", message.getBody())); } if (message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == ChatType.Chat) { try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Example #13
Source File: EaseChatFragment.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
/** * forward message * * @param forward_msg_id */ protected void forwardMessage(String forward_msg_id) { final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id); EMMessage.Type type = forward_msg.getType(); switch (type) { case TXT: if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){ sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(), forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null)); }else{ // get the content and send it String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage(); sendTextMessage(content); } break; case IMAGE: // send image String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl(); if (filePath != null) { File file = new File(filePath); if (!file.exists()) { // send thumb nail if original image does not exist filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath(); } sendImageMessage(filePath); } break; default: break; } if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){ EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo()); } }
Example #14
Source File: EaseChatRowText.java From nono-android with GNU General Public License v3.0 | 5 votes |
protected void handleTextMessage() { if (message.direct() == EMMessage.Direct.SEND) { setMessageSendCallback(); switch (message.status()) { case CREATE: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); // 发送消息 // sendMsgInBackground(message); break; case SUCCESS: // 发送成功 progressBar.setVisibility(View.GONE); statusView.setVisibility(View.GONE); break; case FAIL: // 发送失败 progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case INPROGRESS: // 发送中 progressBar.setVisibility(View.VISIBLE); statusView.setVisibility(View.GONE); break; default: break; } }else{ if(!message.isAcked() && message.getChatType() == ChatType.Chat){ try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { e.printStackTrace(); } } } }
Example #15
Source File: EaseChatFragment.java From nono-android with GNU General Public License v3.0 | 5 votes |
/** * 转发消息 * * @param forward_msg_id */ protected void forwardMessage(String forward_msg_id) { final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id); EMMessage.Type type = forward_msg.getType(); switch (type) { case TXT: if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){ sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(), forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null)); }else{ // 获取消息内容,发送消息 String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage(); sendTextMessage(content); } break; case IMAGE: // 发送图片 String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl(); if (filePath != null) { File file = new File(filePath); if (!file.exists()) { // 不存在大图发送缩略图 filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath(); } sendImageMessage(filePath); } break; default: break; } if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){ EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo()); } }
Example #16
Source File: EaseChatRowText.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
protected void handleTextMessage() { if (message.direct() == EMMessage.Direct.SEND) { setMessageSendCallback(); switch (message.status()) { case CREATE: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case SUCCESS: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.GONE); break; case FAIL: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case INPROGRESS: progressBar.setVisibility(View.VISIBLE); statusView.setVisibility(View.GONE); break; default: break; } }else{ if(!message.isAcked() && message.getChatType() == ChatType.Chat){ try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { e.printStackTrace(); } } } }
Example #17
Source File: EaseChatRowLocation.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
@Override protected void onSetUpView() { locBody = (EMLocationMessageBody) message.getBody(); locationView.setText(locBody.getAddress()); // handle sending message if (message.direct() == EMMessage.Direct.SEND) { setMessageSendCallback(); switch (message.status()) { case CREATE: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case SUCCESS: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.GONE); break; case FAIL: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case INPROGRESS: progressBar.setVisibility(View.VISIBLE); statusView.setVisibility(View.GONE); break; default: break; } }else{ if(!message.isAcked() && message.getChatType() == ChatType.Chat){ try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { e.printStackTrace(); } } } }
Example #18
Source File: EaseAtMessageHelper.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
/** * parse the message, get and save group id if I was mentioned(@) * @param messages */ public void parseMessages(List<EMMessage> messages) { int size = atMeGroupList.size(); EMMessage[] msgs = messages.toArray(new EMMessage[messages.size()]); for(EMMessage msg : msgs){ if(msg.getChatType() == ChatType.GroupChat){ String groupId = msg.getTo(); try { JSONArray jsonArray = msg.getJSONArrayAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG); for(int i = 0; i < jsonArray.length(); i++){ String username = jsonArray.getString(i); if(EMClient.getInstance().getCurrentUser().equals(username)){ if(!atMeGroupList.contains(groupId)){ atMeGroupList.add(groupId); break; } } } } catch (Exception e1) { //Determine whether is @ all message String usernameStr = msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, null); if(usernameStr != null){ if(usernameStr.toUpperCase().equals(EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL)){ if(!atMeGroupList.contains(groupId)){ atMeGroupList.add(groupId); } } } } if(atMeGroupList.size() != size){ EasePreferenceManager.getInstance().setAtMeGroups(atMeGroupList); } } } }
Example #19
Source File: EaseChatRowText.java From Social with Apache License 2.0 | 5 votes |
protected void handleTextMessage() { if (message.direct() == EMMessage.Direct.SEND) { setMessageSendCallback(); switch (message.status()) { case CREATE: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); // 发送消息 // sendMsgInBackground(message); break; case SUCCESS: // 发送成功 progressBar.setVisibility(View.GONE); statusView.setVisibility(View.GONE); break; case FAIL: // 发送失败 progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case INPROGRESS: // 发送中 progressBar.setVisibility(View.VISIBLE); statusView.setVisibility(View.GONE); break; default: break; } }else{ if(!message.isAcked() && message.getChatType() == ChatType.Chat){ try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { e.printStackTrace(); } } } }
Example #20
Source File: EaseChatRowLocation.java From Social with Apache License 2.0 | 5 votes |
@Override protected void onSetUpView() { locBody = (EMLocationMessageBody) message.getBody(); locationView.setText(locBody.getAddress()); // deal with send message if (message.direct() == EMMessage.Direct.SEND) { setMessageSendCallback(); switch (message.status()) { case CREATE: progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); // 发送消息 // sendMsgInBackground(message); break; case SUCCESS: // 发送成功 progressBar.setVisibility(View.GONE); statusView.setVisibility(View.GONE); break; case FAIL: // 发送失败 progressBar.setVisibility(View.GONE); statusView.setVisibility(View.VISIBLE); break; case INPROGRESS: // 发送中 progressBar.setVisibility(View.VISIBLE); statusView.setVisibility(View.GONE); break; default: break; } }else{ if(!message.isAcked() && message.getChatType() == ChatType.Chat){ try { EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (HyphenateException e) { e.printStackTrace(); } } } }
Example #21
Source File: EaseChatFragment.java From Social with Apache License 2.0 | 5 votes |
/** * 转发消息 * * @param forward_msg_id */ protected void forwardMessage(String forward_msg_id) { final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id); EMMessage.Type type = forward_msg.getType(); switch (type) { case TXT: if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){ sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(), forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null)); }else{ // 获取消息内容,发送消息 String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage(); sendTextMessage(content); } break; case IMAGE: // 发送图片 String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl(); if (filePath != null) { File file = new File(filePath); if (!file.exists()) { // 不存在大图发送缩略图 filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath(); } sendImageMessage(filePath); } break; default: break; } if(forward_msg.getChatType() == ChatType.ChatRoom){ EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo()); } }
Example #22
Source File: EaseChatRowVoicePlayClickListener.java From Study_Android_Demo with Apache License 2.0 | 4 votes |
public void playVoice(String filePath) { if (!(new File(filePath).exists())) { return; } playMsgId = message.getMsgId(); AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); mediaPlayer = new MediaPlayer(); if (EaseUI.getInstance().getSettingsProvider().isSpeakerOpened()) { audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(true); mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); } else { audioManager.setSpeakerphoneOn(false);// 关闭扬声器 // 把声音设定成Earpiece(听筒)出来,设定为正在通话中 audioManager.setMode(AudioManager.MODE_IN_CALL); mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); } try { mediaPlayer.setDataSource(filePath); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mediaPlayer.release(); mediaPlayer = null; stopPlayVoice(); // stop animation } }); isPlaying = true; currentPlayListener = this; mediaPlayer.start(); showAnimation(); // 如果是接收的消息 if (message.direct() == EMMessage.Direct.RECEIVE) { if (!message.isAcked() && chatType == ChatType.Chat) { // 告知对方已读这条消息 EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } if (!message.isListened() && iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) { // 隐藏自己未播放这条语音消息的标志 iv_read_status.setVisibility(View.INVISIBLE); message.setListened(true); EMClient.getInstance().chatManager().setMessageListened(message); } } } catch (Exception e) { System.out.println(); } }
Example #23
Source File: EaseChatRowVoicePlayClickListener.java From Social with Apache License 2.0 | 4 votes |
public void playVoice(String filePath) { if (!(new File(filePath).exists())) { return; } playMsgId = message.getMsgId(); AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); mediaPlayer = new MediaPlayer(); //--------------------------- //EaseUI.getInstance(); //--------------------------- if (EaseUI.getInstance().getSettingsProvider().isSpeakerOpened()) { audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(true); mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); } else { audioManager.setSpeakerphoneOn(false);// 关闭扬声器 // 把声音设定成Earpiece(听筒)出来,设定为正在通话中 audioManager.setMode(AudioManager.MODE_IN_CALL); mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); } try { mediaPlayer.setDataSource(filePath); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mediaPlayer.release(); mediaPlayer = null; stopPlayVoice(); // stop animation } }); isPlaying = true; currentPlayListener = this; mediaPlayer.start(); showAnimation(); // 如果是接收的消息 if (message.direct() == EMMessage.Direct.RECEIVE) { if (!message.isAcked() && chatType == ChatType.Chat) { // 告知对方已读这条消息 EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } if (!message.isListened() && iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) { // 隐藏自己未播放这条语音消息的标志 iv_read_status.setVisibility(View.INVISIBLE); message.setListened(true); EMClient.getInstance().chatManager().setMessageListened(message); } } } catch (Exception e) { System.out.println(); } }
Example #24
Source File: EaseChatRowVoicePlayClickListener.java From nono-android with GNU General Public License v3.0 | 4 votes |
public void playVoice(String filePath) { if (!(new File(filePath).exists())) { return; } playMsgId = message.getMsgId(); AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); mediaPlayer = new MediaPlayer(); if (EaseUI.getInstance().getSettingsProvider().isSpeakerOpened()) { audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(true); mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); } else { audioManager.setSpeakerphoneOn(false);// 关闭扬声器 // 把声音设定成Earpiece(听筒)出来,设定为正在通话中 audioManager.setMode(AudioManager.MODE_IN_CALL); mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); } try { mediaPlayer.setDataSource(filePath); mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mediaPlayer.release(); mediaPlayer = null; stopPlayVoice(); // stop animation } }); isPlaying = true; currentPlayListener = this; mediaPlayer.start(); showAnimation(); // 如果是接收的消息 if (message.direct() == EMMessage.Direct.RECEIVE) { if (!message.isAcked() && chatType == ChatType.Chat) { // 告知对方已读这条消息 EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId()); } if (!message.isListened() && iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) { // 隐藏自己未播放这条语音消息的标志 iv_read_status.setVisibility(View.INVISIBLE); message.setListened(true); EMClient.getInstance().chatManager().setMessageListened(message); } } } catch (Exception e) { System.out.println(); } }