From 0b57eb3b68cfdd19f2e8cc391d3d7e9d34b255f0 Mon Sep 17 00:00:00 2001 From: liyuhua <15626451870@163.com> Date: Wed, 22 Nov 2023 17:43:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=A8=A1=E5=9D=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yinmeng-ios/Podfile.lock | 6 +- .../yinmeng-ios.xcodeproj/project.pbxproj | 12 ++ .../Contents.json | 22 +++ ...message_content_audio_playing_first@2x.png | Bin 0 -> 142 bytes ...message_content_audio_playing_first@3x.png | Bin 0 -> 231 bytes .../Contents.json | 22 +++ ...essage_content_audio_playing_second@2x.png | Bin 0 -> 281 bytes ...essage_content_audio_playing_second@3x.png | Bin 0 -> 433 bytes .../Contents.json | 22 +++ ...message_content_audio_playing_third@2x.png | Bin 0 -> 387 bytes ...message_content_audio_playing_third@3x.png | Bin 0 -> 674 bytes .../MewSessionListViewController.m | 19 ++- .../Message/View/Session/MessageAudioCenter.h | 18 ++ .../Message/View/Session/MessageAudioCenter.m | 74 ++++++++ .../View/Session/MessageConentAudioView.h | 16 ++ .../View/Session/MessageConentAudioView.m | 158 ++++++++++++++++++ 16 files changed, 359 insertions(+), 10 deletions(-) create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/Contents.json create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@2x.png create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_first.imageset/mew_message_content_audio_playing_first@3x.png create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/Contents.json create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@2x.png create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_second.imageset/mew_message_content_audio_playing_second@3x.png create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/Contents.json create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@2x.png create mode 100644 yinmeng-ios/yinmeng-ios/Assets.xcassets/Mew/Party/mew_message_content_audio_playing_third.imageset/mew_message_content_audio_playing_third@3x.png create mode 100644 yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.h create mode 100644 yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageAudioCenter.m create mode 100644 yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.h create mode 100644 yinmeng-ios/yinmeng-ios/Main/YinMeng/Message/View/Session/MessageConentAudioView.m 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 0000000000000000000000000000000000000000..ec4fff324a33e63a33fc46449df5456189043a5c GIT binary patch literal 142 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NV3?%C=ER6$FLIFM@u0Yxt479bijf{+d%(JiG zp9YGumIV0)GrXI~)_F>$t{y0$=IP=XqH#W1g0+O{OqUazM3c_Kg+0KphO8u6{1-oD!M<4qzrB literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..9f72620c7d604c5c7e12ce7d8775d6031dd096f8 GIT binary patch literal 231 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw3=&b&bO2Ju0X`wFAQ}vejEoEo4S}Skr6o`R z$N-WiCML)XpaP(v(A+(Tf!YL0g8YIRe&6eL(&l|OE5_$)eu$OmvsLq-0p)@{T^vI^ zj=#O+$<^S%;}U4??C)3l|8kdtNuKhTV^zQT6;C?3xa^<0cl$Nl_FK-Z8duLbyxFD3 z5Tq+G`;KnVO{R~1?dSTA-`Ff}=J)lbXGcfJJ-s*==9Qn8B!vKtXYh3Ob6Mw<&;$UK CSxT}1 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a69b3773ccab4ca30b635fe503c0a3d9566a9c3a GIT binary patch literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU3?z3ec*FxKn*g5>S0HU{Y;0&~2q%FIBO@aq zi3}hj5M^-j2m{|>pnlsyPJbqt*(v_Yrjv*GO z-%hsXYcSw(_OzcMmeF|U|2h@s>?e&&gKSePCOxj1wlYw}>(Gwq4#5eoEm92M);#Ij zF@I54$IoR6ejamTPrhQDsKKTy$I5^HQ}((D8Fm$B&+Zi8Lkc;)Ei1*?mdKI;Vst052t4mjD0& literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..7d958a357ef3af55f710c1b13f2536b5113e8b21 GIT binary patch literal 433 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw3=&b&bO2Jx0X`wFK-w4#j9>uH1u|e_Mi4<0 z6BCFakOZ=gC*Z=Y1=oa zHdpY&ZG-dWX&$TmRE|!V7Jme&_O7RkV~EG`w^Jke4lD4uoW8}f>3#Li|C+NcY#F4M zcukyPUvE>{lUU*E>T2usM}pP;X2~>Pu1i^`Bjeu)oE3gN=W;aH!PB?ro_Z~~@N$>n z-4up7Tjdw6Uc&q$Sx!PyyrWPt^UcY!A2;3y{rJ8)cXrSB8&`JePkG-KVwst{kNBo;)34fWQ S=Zrv)GI+ZBxvXQS0JsYr)LZUhK7bfCWJIG zF#)oTjErECSZIhExU%EoVRL{cN|prq1v9X|`#Dkgt^$wQr;hxz$Cr+7SvAMipgcqO zI=grjP|;~m7sn8b(@&?|(U?QdH8KwoqFfO68XQ2b3d~m zFY8X;5$M9^-{AShMsl+BiDrh|?M=b)uIIMj^7YCq4OVmF;3}JXX7MZEL*0%`e@d0i zef9oBopa~94Qs?#H@QzqZk;12y$><5D^h^As+I)#1v9XI=hk`?_DI02J@>Zrr;}c? z*ZXQ?4{W>;pq#pMs-)<$rg?M9RZch`VPIg~<>}%W;&J?K*zLS#10G#Z4o{A9jp_Fm zhmmW0l5O%&~qJ3&ZAbOif9p+ombzw%M$gKKs$M z>CqaAhgybmdKI;Vst0BG9_{Qv*} literal 0 HcmV?d00001 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