注册

iOS语音聊天的问题, 有哪位大神耐心求教

我们的需求是在A界面发送一条语音, 然后在B界面可以听自己发送过的语音, C界面可以听别人发给我的语音, 我现在可以把语音发出去, 如果集成单聊界面的话也能收到发出去的语音, 可是不使用单聊界面而是在其他页面收听语音做了好久也没做出来, 求大神帮帮忙
已邀请:
只要获取到这条语音消息,下载语音后,调用该方法即可,// 播放音频
- (void)asyncPlayingWithPath:(NSString *)aFilePath
                  completion:(void(^)(NSError *error))completon{
你要想在任何页面收听语音消息,首先你要有这条语音消息,然后在点击的时候直接简单粗暴的调用以下代码就行。
至于EMCDDeviceManager这个类是环信封装的一个第三方开源类,在官方开源代码里能找到
-(void)audioAction:(EMMessage *)aMessage
{
id <IEMFileMessageBody> body = [aMessage.messageBodies firstObject];
EMAttachmentDownloadStatus downloadStatus = [body attachmentDownloadStatus];
if (downloadStatus == EMAttachmentDownloading) {
//正在下载,请稍等
return;
}
else if (downloadStatus == EMAttachmentDownloadFailure)
{
//下载失败,重新下载
[[EaseMob sharedInstance].chatManager asyncFetchMessage:aMessage
progress:nil];

return;
}

if (body.messageBodyType == eMessageBodyType_Voice) {
//开启红外线检测
[[EMCDDeviceManager sharedInstance] enableProximitySensor];
//播放语音
EMChatVoice *chatVoice = (EMChatVoice *)((EMVoiceMessageBody *)body).chatObject;
[[EMCDDeviceManager sharedInstance] asyncPlayingWithPath:
aMessage.chatVoice.localPath completion:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
//关闭红外线检测
[[EMCDDeviceManager sharedInstance] disableProximitySensor];
});
}];
}
}

要回复问题请先登录注册