Android环信自动播放下一条语音
******************************** 为了观看代码质量,请复制到文档中观看*************************
****** 本人为了更好的实现EaseChatFragment,用一个子类ChatFragment继承了EaseChatFragment*******
[1]:重写onMessageBubbleClick()--
判断if(type == EMMessage.Type.VOICE.ordinal()&& message.direct() == EMMessage.Direct.RECEIVE){ // 是语音 并且是接受到的
List emMessages= conversation.getAllMessages();
Log.d("AA", "开始遍历");
position = conversation.getMessagePosition(message); // position 的获取
EaseChatRowVoice easeChatRowVoice = new EaseChatRowVoice(getActivity(), message, position, eAdapter, conversation); // 在EaseChatRowVoice添加参数conversation
easeChatRowVoice.onBubbleClick();
return true; //返回true 自行处理事件
}
//* EaseChatRowVoice参数介绍: position: conversation.getMessagePosition(message); eAdapter: 通过参数传递过来*/
// ** eAdapter的获取: 在EaseChatMessageList中创建方法
(1). public EaseMessageAdapter getAdapter() {
return messageAdapter;
}
(2). 可以在EaseChatFragment中找到 messageList = (EaseChatMessageList) getView().findViewById(R.id.message_list);控件对象
(3). 在setListItemClickListener------> onBubbleClick()方法中添加
public boolean onBubbleClick(EMMessage message) { // 条目点击事件
if (chatFragmentListener != null) {
eAdapter = messageList.getAdapter();
return chatFragmentListener.onMessageBubbleClick(message, eAdapter); // EaseChatFragmentListener chatFragmentListener
}
return false;
}
(4). 在ChatFragment中的onMessageBubbleClick()即可得到eAdapter!!!!!!!
*************不要忘记修改接口EaseChatFragmentListener 中onMessageBubbleClick中的参数***********
// ** conversation参数或获取: conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername,EaseCommonUtils.getConversationType(chatType), true);
// getConversation参数介绍: toChatUsername: 正要去交谈的对象的环信ID.
chatType: // 判断单聊还是群聊
chatType = fragmentArgs.getInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE); 注解:/*(EaseConstant.EXTRA_CHAT_TYPE = "chatType")*/
注解: fragmentArgs = getArguments();
[2]: 在EaseChatRowVoice中onBubbleClick()方法 注解: 传递增加的参数
改为: new EaseChatRowVoicePlayClickListener(message, voiceImageView, readStutausView, adapter, activity, position,conversation).onClick(bubbleLayout);
[3]: EaseChatRowVoicePlayClickListener构造中获取传递的参数: conversation adapter 等!! --- > 在EaseChatRowVoicePlayClickListener中的playVoice()中的setOnCompletionListener的onCompletion中添加如下:
public void onCompletion(MediaPlayer mp) {
mediaPlayer.release();
mediaPlayer = null;
stopPlayVoice(); // stop animation
List emMessages = conversation.getAllMessages();
EMMessage emMessage_last = conversation.getLastMessage();
if(message.equals(emMessage_last)){ // 判断如果是最后一条语音则不做处理
Log.d("AA", "最后一个信息");
}else{
EMMessage emMessage1 = emMessages.get(position + 1);
int type = emMessage1.getType().ordinal();
if(emMessage1 != null){
if(type == EMMessage.Type.VOICE.ordinal()&& message.direct() == EMMessage.Direct.RECEIVE){ // 判断是否是接收到语音
EaseChatRowVoice easeChatRowVoice = new EaseChatRowVoice(activity, emMessage1, position + 1, adapter, conversation);
easeChatRowVoice.onBubbleClick();
}
}
}
}
*******************************************************************************************************************************bug处理 ********************************************************
在操作完所有的步骤之后,会出现语音可以播放但是动画效果却没有执行,原因是:adapter没有刷新,解决办法如下:
在EaseChatRowVoicePlayClickListener下的showAnimation()中voiceIconView.setImageResource(R.anim.voice_from_icon);(showAnimation()第二行后面)这句话的后面添加此句: adapter.notifyDataSetChanged();
*本帖子不收任何费用,代码纯属原创 转载请说明出处 如有运行问题可与我联系 本人姓氏: 侯 邮箱:277667430@qq.com**
****** 本人为了更好的实现EaseChatFragment,用一个子类ChatFragment继承了EaseChatFragment*******
[1]:重写onMessageBubbleClick()--
判断if(type == EMMessage.Type.VOICE.ordinal()&& message.direct() == EMMessage.Direct.RECEIVE){ // 是语音 并且是接受到的
List
Log.d("AA", "开始遍历");
position = conversation.getMessagePosition(message); // position 的获取
EaseChatRowVoice easeChatRowVoice = new EaseChatRowVoice(getActivity(), message, position, eAdapter, conversation); // 在EaseChatRowVoice添加参数conversation
easeChatRowVoice.onBubbleClick();
return true; //返回true 自行处理事件
}
//* EaseChatRowVoice参数介绍: position: conversation.getMessagePosition(message); eAdapter: 通过参数传递过来*/
// ** eAdapter的获取: 在EaseChatMessageList中创建方法
(1). public EaseMessageAdapter getAdapter() {
return messageAdapter;
}
(2). 可以在EaseChatFragment中找到 messageList = (EaseChatMessageList) getView().findViewById(R.id.message_list);控件对象
(3). 在setListItemClickListener------> onBubbleClick()方法中添加
public boolean onBubbleClick(EMMessage message) { // 条目点击事件
if (chatFragmentListener != null) {
eAdapter = messageList.getAdapter();
return chatFragmentListener.onMessageBubbleClick(message, eAdapter); // EaseChatFragmentListener chatFragmentListener
}
return false;
}
(4). 在ChatFragment中的onMessageBubbleClick()即可得到eAdapter!!!!!!!
*************不要忘记修改接口EaseChatFragmentListener 中onMessageBubbleClick中的参数***********
// ** conversation参数或获取: conversation = EMClient.getInstance().chatManager().getConversation(toChatUsername,EaseCommonUtils.getConversationType(chatType), true);
// getConversation参数介绍: toChatUsername: 正要去交谈的对象的环信ID.
chatType: // 判断单聊还是群聊
chatType = fragmentArgs.getInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE); 注解:/*(EaseConstant.EXTRA_CHAT_TYPE = "chatType")*/
注解: fragmentArgs = getArguments();
[2]: 在EaseChatRowVoice中onBubbleClick()方法 注解: 传递增加的参数
改为: new EaseChatRowVoicePlayClickListener(message, voiceImageView, readStutausView, adapter, activity, position,conversation).onClick(bubbleLayout);
[3]: EaseChatRowVoicePlayClickListener构造中获取传递的参数: conversation adapter 等!! --- > 在EaseChatRowVoicePlayClickListener中的playVoice()中的setOnCompletionListener的onCompletion中添加如下:
public void onCompletion(MediaPlayer mp) {
mediaPlayer.release();
mediaPlayer = null;
stopPlayVoice(); // stop animation
List
EMMessage emMessage_last = conversation.getLastMessage();
if(message.equals(emMessage_last)){ // 判断如果是最后一条语音则不做处理
Log.d("AA", "最后一个信息");
}else{
EMMessage emMessage1 = emMessages.get(position + 1);
int type = emMessage1.getType().ordinal();
if(emMessage1 != null){
if(type == EMMessage.Type.VOICE.ordinal()&& message.direct() == EMMessage.Direct.RECEIVE){ // 判断是否是接收到语音
EaseChatRowVoice easeChatRowVoice = new EaseChatRowVoice(activity, emMessage1, position + 1, adapter, conversation);
easeChatRowVoice.onBubbleClick();
}
}
}
}
*******************************************************************************************************************************bug处理 ********************************************************
在操作完所有的步骤之后,会出现语音可以播放但是动画效果却没有执行,原因是:adapter没有刷新,解决办法如下:
在EaseChatRowVoicePlayClickListener下的showAnimation()中voiceIconView.setImageResource(R.anim.voice_from_icon);(showAnimation()第二行后面)这句话的后面添加此句: adapter.notifyDataSetChanged();
*本帖子不收任何费用,代码纯属原创 转载请说明出处 如有运行问题可与我联系 本人姓氏: 侯 邮箱:277667430@qq.com**
没有找到相关结果
已邀请:
0 个回复