diff --git a/yinmeng-ios/Podfile.lock b/yinmeng-ios/Podfile.lock index 74e1d66..01f05a0 100644 --- a/yinmeng-ios/Podfile.lock +++ b/yinmeng-ios/Podfile.lock @@ -32,7 +32,7 @@ PODS: - NTESQuickPass (3.4.5): - NTESBaseComponent - pop (1.0.12) - - Protobuf (3.24.4) + - Protobuf (3.25.0) - QGVAPlayer (1.0.19) - Qiniu (8.7.0): - HappyDNS (~> 1.0.3) @@ -140,7 +140,7 @@ SPEC CHECKSUMS: NTESBaseComponent: 7b310e7e80bb6c27183176188b98356d200dbbc5 NTESQuickPass: 7baf2a68a091fd69dbf70b84ecdc4eb6aa7dd7ad pop: d582054913807fd11fd50bfe6a539d91c7e1a55a - Protobuf: 351e9022fe13a6e2af00e9aefc22077cb88520f8 + Protobuf: 6a4183ec1d51649eb2be7b86ccc286e5c539219c QGVAPlayer: a0bca68c9bd6f1c8de5ac2d10ddf98be6038cce9 Qiniu: da7204f1bf7d0ce18f2b8c541c7fafb301aab624 QY_NIM_iOS_SDK: 7fbf411c9c299f3b904fcc5b494542f41a11f70c @@ -156,4 +156,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: cc88fa05da662ee682fc0eeb502faab221faa032 -COCOAPODS: 1.14.2 +COCOAPODS: 1.12.1 diff --git a/yinmeng-ios/yinmeng-ios.xcodeproj/project.pbxproj b/yinmeng-ios/yinmeng-ios.xcodeproj/project.pbxproj index 13eae36..5a51985 100644 --- a/yinmeng-ios/yinmeng-ios.xcodeproj/project.pbxproj +++ b/yinmeng-ios/yinmeng-ios.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 23270C292B0E037300B9303B /* MessageConentAudioView.m in Sources */ = {isa = PBXBuildFile; fileRef = 23270C272B0E037300B9303B /* MessageConentAudioView.m */; }; + 23270C2C2B0E041300B9303B /* MessageAudioCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 23270C2B2B0E041300B9303B /* MessageAudioCenter.m */; }; 233757562B0CB577001D0B7F /* MessagePresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 233757262B0CB577001D0B7F /* MessagePresenter.m */; }; 233757572B0CB577001D0B7F /* MessageMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2337572C2B0CB577001D0B7F /* MessageMenuModel.m */; }; 233757582B0CB577001D0B7F /* ChatLimitModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2337572D2B0CB577001D0B7F /* ChatLimitModel.m */; }; @@ -191,6 +193,10 @@ /* Begin PBXFileReference section */ 1797344FB85F47F60D0CC2A0 /* Pods_yinmeng_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_yinmeng_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 23270C272B0E037300B9303B /* MessageConentAudioView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageConentAudioView.m; sourceTree = ""; }; + 23270C282B0E037300B9303B /* MessageConentAudioView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageConentAudioView.h; sourceTree = ""; }; + 23270C2A2B0E041300B9303B /* MessageAudioCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageAudioCenter.h; sourceTree = ""; }; + 23270C2B2B0E041300B9303B /* MessageAudioCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageAudioCenter.m; sourceTree = ""; }; 233757262B0CB577001D0B7F /* MessagePresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessagePresenter.m; sourceTree = ""; }; 233757272B0CB577001D0B7F /* MessagePresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePresenter.h; sourceTree = ""; }; 233757292B0CB577001D0B7F /* MessageProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageProtocol.h; sourceTree = ""; }; @@ -659,6 +665,10 @@ 233757372B0CB577001D0B7F /* Session */ = { isa = PBXGroup; children = ( + 23270C2A2B0E041300B9303B /* MessageAudioCenter.h */, + 23270C2B2B0E041300B9303B /* MessageAudioCenter.m */, + 23270C282B0E037300B9303B /* MessageConentAudioView.h */, + 23270C272B0E037300B9303B /* MessageConentAudioView.m */, 233757382B0CB577001D0B7F /* SessionNavView.h */, 233757392B0CB577001D0B7F /* SessionMessageCell.m */, 2337573A2B0CB577001D0B7F /* SessionAudioRecordView.h */, @@ -2259,6 +2269,7 @@ 8C9C84A72B0D920700A601BC /* MicroWaveView.m in Sources */, 8C9C82BC2B0C695600A601BC /* UserInfoModel.m in Sources */, 8C9C84602B0C697A00A601BC /* MewVoiceGuideView.m in Sources */, + 23270C292B0E037300B9303B /* MessageConentAudioView.m in Sources */, 8C9C84312B0C697A00A601BC /* MewSessionListViewController.m in Sources */, 8C9C82AB2B0C695600A601BC /* NetImageConfig.m in Sources */, 8C9C84892B0D286F00A601BC /* Api+Gift.m in Sources */, @@ -2305,6 +2316,7 @@ 8C9C841F2B0C697A00A601BC /* StageView.m in Sources */, 8C9C844D2B0C697A00A601BC /* LoginForgetPasswordPresent.m in Sources */, 8C9C82C12B0C695600A601BC /* Api.m in Sources */, + 23270C2C2B0E041300B9303B /* MessageAudioCenter.m in Sources */, 8C9C844A2B0C697A00A601BC /* Api+Mine.m in Sources */, 8C9C82A82B0C695600A601BC /* BaseViewController.m in Sources */, 8C9C82C72B0C695600A601BC /* NSMutableDictionary+Safe.m in Sources */, diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/Contents.json b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/Contents.json new file mode 100644 index 0000000..d13138a --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "mew_message_content_audio_playing_first@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "mew_message_content_audio_playing_first@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@2x.png b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@2x.png new file mode 100644 index 0000000..ec4fff3 Binary files /dev/null and b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@2x.png differ diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@3x.png b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@3x.png new file mode 100644 index 0000000..9f72620 Binary files /dev/null and b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@3x.png differ diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/Contents.json b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/Contents.json new file mode 100644 index 0000000..3c7b8c4 --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "mew_message_content_audio_playing_second@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "mew_message_content_audio_playing_second@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@2x.png b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@2x.png new file mode 100644 index 0000000..a69b377 Binary files /dev/null and b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@2x.png differ diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@3x.png b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@3x.png new file mode 100644 index 0000000..7d958a3 Binary files /dev/null and b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@3x.png differ diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/Contents.json b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/Contents.json new file mode 100644 index 0000000..aa03669 --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "mew_message_content_audio_playing_third@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "mew_message_content_audio_playing_third@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@2x.png b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@2x.png new file mode 100644 index 0000000..4c10fb9 Binary files /dev/null and b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@2x.png differ diff --git a/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@3x.png b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@3x.png new file mode 100644 index 0000000..f787a05 Binary files /dev/null and b/yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@3x.png differ diff --git a/yinmeng-ios/yinmeng-ios/Main/Mew/Message/View/SessionList/MewSessionListViewController.m b/yinmeng-ios/yinmeng-ios/Main/Mew/Message/View/SessionList/MewSessionListViewController.m index 874ad3c..e144420 100644 --- a/yinmeng-ios/yinmeng-ios/Main/Mew/Message/View/SessionList/MewSessionListViewController.m +++ b/yinmeng-ios/yinmeng-ios/Main/Mew/Message/View/SessionList/MewSessionListViewController.m @@ -68,13 +68,18 @@ - (void)loadSessionData { NSArray *allRecentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy]; __block int unreadCount = 0; + NSArray *getList ; + + + NSMutableArray* sessionList = [NSMutableArray array]; [allRecentSessions enumerateObjectsUsingBlock:^(NIMRecentSession * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - if (![[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:obj.session.sessionId]) { - if (obj.session.sessionId.integerValue > 0) { - [sessionList addObject:obj]; - unreadCount += obj.unreadCount; - } + if ([[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:obj.session.sessionId] || [[ClientConfig shareConfig].configInfo.officialAccountUids containsObject:obj.session.sessionId]) { + return; + } + if (obj.session.sessionId.integerValue > 0 ) { + [sessionList addObject:obj]; + unreadCount += obj.unreadCount; } }]; @@ -105,7 +110,7 @@ /// 增加最近会话完成 - (void)didAddRecentSession:(NIMRecentSession *)recentSession totalUnreadCount:(NSInteger)totalUnreadCount { // 判断是否是官方账号 - if ([[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:recentSession.session.sessionId]) { + if ([[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:recentSession.session.sessionId] || [[ClientConfig shareConfig].configInfo.officialAccountUids containsObject:recentSession.session.sessionId]) { return; } @@ -134,7 +139,7 @@ /// 最近会话修改完成 - (void)didUpdateRecentSession:(NIMRecentSession *)recentSession totalUnreadCount:(NSInteger)totalUnreadCount { // 判断是否是官方账号 - if ([[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:recentSession.session.sessionId]) { + if ([[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:recentSession.session.sessionId] || [[ClientConfig shareConfig].configInfo.officialAccountUids containsObject:recentSession.session.sessionId]) { return; } diff --git a/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.h b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.h new file mode 100644 index 0000000..a1913f4 --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.h @@ -0,0 +1,18 @@ +// +// MessageAudioCenter.h +// xplan-ios +// +// Created by 冯硕 on 2022/4/22. +// + +#import + +NS_ASSUME_NONNULL_BEGIN +@class NIMMessage; +@interface MessageAudioCenter : NSObject ++ (instancetype)shareInstance; +@property (nonatomic,strong, readonly) NIMMessage *currentPlayingMessage; +- (void)play:(NIMMessage *)message; +@end + +NS_ASSUME_NONNULL_END diff --git a/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.m b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.m new file mode 100644 index 0000000..98c3b33 --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.m @@ -0,0 +1,74 @@ +// +// MessageAudioCenter.m +// xplan-ios +// +// Created by 冯硕 on 2022/4/22. +// + +#import "MessageAudioCenter.h" +#import + +@interface MessageAudioCenter () +@property (nonatomic,assign) NSInteger retryCount; +@property (nonatomic,strong,nullable) NIMMessage *currentPlayingMessage; +@end + +@implementation MessageAudioCenter + ++ (instancetype)shareInstance { + static MessageAudioCenter *instance; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[MessageAudioCenter alloc] init]; + }); + return instance; +} + +- (instancetype)init { + self = [super init]; + if (self) { + [[NIMSDK sharedSDK].mediaManager addDelegate:self]; + [self resetRetryCount]; + } + return self; +} + +- (void)resetRetryCount { + _retryCount = 3; +} + +- (void)play:(NIMMessage *)message { + NIMAudioObject *audioObject = (NIMAudioObject *)message.messageObject; + if ([audioObject isKindOfClass:[NIMAudioObject class]]) { + self.currentPlayingMessage = message; + message.isPlayed = YES; + [[NIMSDK sharedSDK].mediaManager play:audioObject.path]; + } +} + + +#pragma mark - NIMMediaManagerDelegate + +- (void)playAudio:(NSString *)filePath didBeganWithError:(NSError *)error +{ + if (error) { + if (_retryCount > 0){ + // iPhone4 和 iPhone 4S 上连播会由于设备释放过慢导致 AudioQueue 启动不了的问题,这里做个延迟重试,最多重试 3 次 ( code -66681 ) + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[NIMSDK sharedSDK].mediaManager play:filePath]; + }); + }else{ + self.currentPlayingMessage = nil; + [self resetRetryCount]; + } + } else { + [self resetRetryCount]; + } +} + +- (void)playAudio:(NSString *)filePath didCompletedWithError:(nullable NSError *)error { + self.currentPlayingMessage = nil; +} + + +@end diff --git a/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.h b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.h new file mode 100644 index 0000000..2b4e33e --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.h @@ -0,0 +1,16 @@ +// +// MessageConentAudioView.h +// xplan-ios +// +// Created by 冯硕 on 2022/4/22. +// + +#import +#import "MessageContentProtocol.h" +NS_ASSUME_NONNULL_BEGIN + +@interface MessageConentAudioView : UIView + +@end + +NS_ASSUME_NONNULL_END diff --git a/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.m b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.m new file mode 100644 index 0000000..dfc7e90 --- /dev/null +++ b/yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.m @@ -0,0 +1,158 @@ +// +// MessageConentAudioView.m +// xplan-ios +// +// Created by 冯硕 on 2022/4/22. +// + +#import "MessageConentAudioView.h" +///Third +#import +#import +///Tool +#import "ThemeColor.h" +#import "MessageAudioCenter.h" +@interface MessageConentAudioView () +///背景 +@property (nonatomic,strong) UIView * backView; +///显示语音的时长 +@property (nonatomic,strong) UILabel *timeLabel; +///显示语音的动画 +@property (nonatomic,strong) UIImageView *audioImageView; +///当前的消息 +@property (nonatomic,strong) NIMMessage *message; +///是否正在播放 +@property (nonatomic,assign) BOOL isPlaying; +@end + +@implementation MessageConentAudioView + +- (void)dealloc { + [[NIMSDK sharedSDK].mediaManager removeDelegate:self]; +} + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [[NIMSDK sharedSDK].mediaManager setNeedProximityMonitor:NO]; + [[NIMSDK sharedSDK].mediaManager addDelegate:self]; + [self initSubViews]; + [self initSubViewConstraints]; + } + return self; +} +#pragma mark - Private Method +- (void)initSubViews { + [self addSubview:self.backView]; + [self.backView addSubview:self.timeLabel]; + [self.backView addSubview:self.audioImageView]; +} + +- (void)initSubViewConstraints { + [self.backView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(MESSAGE_PADDING, MESSAGE_PADDING, MESSAGE_PADDING, MESSAGE_PADDING)); + make.height.mas_equalTo(30); + make.width.mas_equalTo(50); + }]; + + [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.mas_equalTo(self.backView).offset(10); + make.centerY.mas_equalTo(self.backView); + }]; + + [self.audioImageView mas_makeConstraints:^(MASConstraintMaker *make) { + make.size.mas_equalTo(CGSizeMake(20, 20)); + make.right.mas_equalTo(self.backView).offset(-10); + make.centerY.mas_equalTo(self.backView); + }]; +} + +#pragma mark - NIMMediaManagerDelegate +- (void)playAudio:(NSString *)filePath didBeganWithError:(NSError *)error { + if(filePath && !error) { + if ([MessageAudioCenter shareInstance].currentPlayingMessage == self.message) { + [self.audioImageView startAnimating]; + } + } +} + +- (void)playAudio:(NSString *)filePath didCompletedWithError:(NSError *)error { + [self.audioImageView stopAnimating]; + UIImage * thirdImage = [UIImage imageNamed:@"mew_message_content_audio_playing_third"]; + self.audioImageView.image = thirdImage; +} +#pragma mark - Event Response +- (void)didTapBackRecognizer { + if ([self.message attachmentDownloadState] == NIMMessageAttachmentDownloadStateDownloaded) { + if ([[NIMSDK sharedSDK].mediaManager isPlaying]) { + [[NIMSDK sharedSDK].mediaManager stopPlay]; + } + + if (self.isPlaying) { + [[NIMSDK sharedSDK].mediaManager stopPlay]; + self.isPlaying = NO; + } else { + self.isPlaying = YES; + [[NIMSDK sharedSDK].mediaManager switchAudioOutputDevice:NIMAudioOutputDeviceSpeaker]; + [[MessageAudioCenter shareInstance] play:self.message]; + } + } +} + +#pragma mark - Getters And Setters +- (UIView *)backView { + if (!_backView) { + _backView = [[UIView alloc] init]; + _backView.backgroundColor = [UIColor clearColor]; + UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapBackRecognizer)]; + [_backView addGestureRecognizer:tap]; + } + return _backView; +} + +- (UILabel *)timeLabel { + if (!_timeLabel) { + _timeLabel = [[UILabel alloc] init]; + _timeLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium]; + _timeLabel.textColor = [ThemeColor mainTextColor]; + } + return _timeLabel; +} + +- (UIImageView *)audioImageView { + if (!_audioImageView) { + _audioImageView = [[UIImageView alloc] init]; + _audioImageView.userInteractionEnabled = YES; + UIImage * firstImage = [UIImage imageNamed:@"mew_message_content_audio_playing_first"]; + UIImage * secondImage = [UIImage imageNamed:@"mew_message_content_audio_playing_second"]; + UIImage * thirdImage = [UIImage imageNamed:@"mew_message_content_audio_playing_third"]; + _audioImageView.animationImages = @[firstImage, secondImage, thirdImage]; + _audioImageView.animationDuration = 1; + _audioImageView.animationRepeatCount = HUGE; + _audioImageView.image = thirdImage; + } + return _audioImageView; +} + ++ (CGFloat)measureHeight:(NIMMessage *)message { + NSInteger audioContentHeight = 30; + return (audioContentHeight + CONTENT_PADDING_V_TOTAL+ MESSAGE_PADDING * 2); +} + +- (void)render:(NIMMessage *)message { + self.message = message; + NIMAudioObject *audioContent = (NIMAudioObject*)[message messageObject]; + NSAssert([audioContent isKindOfClass:[NIMAudioObject class]], @"message should be audio"); + CGFloat value = 2*atan((audioContent.duration/1000.0-1)/10.0)/M_PI; + NSInteger audioContentMinWidth = (CONTENT_WIDTH_MAX - 180); + NSInteger audioContentMaxWidth = (CONTENT_WIDTH_MAX - 100); + CGFloat audioWidth = (audioContentMaxWidth - audioContentMinWidth)* value + audioContentMinWidth; + [self.backView mas_updateConstraints:^(MASConstraintMaker *make) { + make.width.mas_equalTo(audioWidth);; + }]; + self.timeLabel.text = [NSString stringWithFormat:@"%zd\"",(audioContent.duration+500)/1000];//四舍五入 +} + + + +@end