消息模块优化
This commit is contained in:
@@ -32,7 +32,7 @@ PODS:
|
|||||||
- NTESQuickPass (3.4.5):
|
- NTESQuickPass (3.4.5):
|
||||||
- NTESBaseComponent
|
- NTESBaseComponent
|
||||||
- pop (1.0.12)
|
- pop (1.0.12)
|
||||||
- Protobuf (3.24.4)
|
- Protobuf (3.25.0)
|
||||||
- QGVAPlayer (1.0.19)
|
- QGVAPlayer (1.0.19)
|
||||||
- Qiniu (8.7.0):
|
- Qiniu (8.7.0):
|
||||||
- HappyDNS (~> 1.0.3)
|
- HappyDNS (~> 1.0.3)
|
||||||
@@ -140,7 +140,7 @@ SPEC CHECKSUMS:
|
|||||||
NTESBaseComponent: 7b310e7e80bb6c27183176188b98356d200dbbc5
|
NTESBaseComponent: 7b310e7e80bb6c27183176188b98356d200dbbc5
|
||||||
NTESQuickPass: 7baf2a68a091fd69dbf70b84ecdc4eb6aa7dd7ad
|
NTESQuickPass: 7baf2a68a091fd69dbf70b84ecdc4eb6aa7dd7ad
|
||||||
pop: d582054913807fd11fd50bfe6a539d91c7e1a55a
|
pop: d582054913807fd11fd50bfe6a539d91c7e1a55a
|
||||||
Protobuf: 351e9022fe13a6e2af00e9aefc22077cb88520f8
|
Protobuf: 6a4183ec1d51649eb2be7b86ccc286e5c539219c
|
||||||
QGVAPlayer: a0bca68c9bd6f1c8de5ac2d10ddf98be6038cce9
|
QGVAPlayer: a0bca68c9bd6f1c8de5ac2d10ddf98be6038cce9
|
||||||
Qiniu: da7204f1bf7d0ce18f2b8c541c7fafb301aab624
|
Qiniu: da7204f1bf7d0ce18f2b8c541c7fafb301aab624
|
||||||
QY_NIM_iOS_SDK: 7fbf411c9c299f3b904fcc5b494542f41a11f70c
|
QY_NIM_iOS_SDK: 7fbf411c9c299f3b904fcc5b494542f41a11f70c
|
||||||
@@ -156,4 +156,4 @@ SPEC CHECKSUMS:
|
|||||||
|
|
||||||
PODFILE CHECKSUM: cc88fa05da662ee682fc0eeb502faab221faa032
|
PODFILE CHECKSUM: cc88fa05da662ee682fc0eeb502faab221faa032
|
||||||
|
|
||||||
COCOAPODS: 1.14.2
|
COCOAPODS: 1.12.1
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* 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 */; };
|
233757562B0CB577001D0B7F /* MessagePresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 233757262B0CB577001D0B7F /* MessagePresenter.m */; };
|
||||||
233757572B0CB577001D0B7F /* MessageMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2337572C2B0CB577001D0B7F /* MessageMenuModel.m */; };
|
233757572B0CB577001D0B7F /* MessageMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2337572C2B0CB577001D0B7F /* MessageMenuModel.m */; };
|
||||||
233757582B0CB577001D0B7F /* ChatLimitModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2337572D2B0CB577001D0B7F /* ChatLimitModel.m */; };
|
233757582B0CB577001D0B7F /* ChatLimitModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2337572D2B0CB577001D0B7F /* ChatLimitModel.m */; };
|
||||||
@@ -191,6 +193,10 @@
|
|||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
1797344FB85F47F60D0CC2A0 /* Pods_yinmeng_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_yinmeng_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
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 = "<group>"; };
|
||||||
|
23270C282B0E037300B9303B /* MessageConentAudioView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageConentAudioView.h; sourceTree = "<group>"; };
|
||||||
|
23270C2A2B0E041300B9303B /* MessageAudioCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageAudioCenter.h; sourceTree = "<group>"; };
|
||||||
|
23270C2B2B0E041300B9303B /* MessageAudioCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessageAudioCenter.m; sourceTree = "<group>"; };
|
||||||
233757262B0CB577001D0B7F /* MessagePresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessagePresenter.m; sourceTree = "<group>"; };
|
233757262B0CB577001D0B7F /* MessagePresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessagePresenter.m; sourceTree = "<group>"; };
|
||||||
233757272B0CB577001D0B7F /* MessagePresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePresenter.h; sourceTree = "<group>"; };
|
233757272B0CB577001D0B7F /* MessagePresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePresenter.h; sourceTree = "<group>"; };
|
||||||
233757292B0CB577001D0B7F /* MessageProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageProtocol.h; sourceTree = "<group>"; };
|
233757292B0CB577001D0B7F /* MessageProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageProtocol.h; sourceTree = "<group>"; };
|
||||||
@@ -659,6 +665,10 @@
|
|||||||
233757372B0CB577001D0B7F /* Session */ = {
|
233757372B0CB577001D0B7F /* Session */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
23270C2A2B0E041300B9303B /* MessageAudioCenter.h */,
|
||||||
|
23270C2B2B0E041300B9303B /* MessageAudioCenter.m */,
|
||||||
|
23270C282B0E037300B9303B /* MessageConentAudioView.h */,
|
||||||
|
23270C272B0E037300B9303B /* MessageConentAudioView.m */,
|
||||||
233757382B0CB577001D0B7F /* SessionNavView.h */,
|
233757382B0CB577001D0B7F /* SessionNavView.h */,
|
||||||
233757392B0CB577001D0B7F /* SessionMessageCell.m */,
|
233757392B0CB577001D0B7F /* SessionMessageCell.m */,
|
||||||
2337573A2B0CB577001D0B7F /* SessionAudioRecordView.h */,
|
2337573A2B0CB577001D0B7F /* SessionAudioRecordView.h */,
|
||||||
@@ -2259,6 +2269,7 @@
|
|||||||
8C9C84A72B0D920700A601BC /* MicroWaveView.m in Sources */,
|
8C9C84A72B0D920700A601BC /* MicroWaveView.m in Sources */,
|
||||||
8C9C82BC2B0C695600A601BC /* UserInfoModel.m in Sources */,
|
8C9C82BC2B0C695600A601BC /* UserInfoModel.m in Sources */,
|
||||||
8C9C84602B0C697A00A601BC /* MewVoiceGuideView.m in Sources */,
|
8C9C84602B0C697A00A601BC /* MewVoiceGuideView.m in Sources */,
|
||||||
|
23270C292B0E037300B9303B /* MessageConentAudioView.m in Sources */,
|
||||||
8C9C84312B0C697A00A601BC /* MewSessionListViewController.m in Sources */,
|
8C9C84312B0C697A00A601BC /* MewSessionListViewController.m in Sources */,
|
||||||
8C9C82AB2B0C695600A601BC /* NetImageConfig.m in Sources */,
|
8C9C82AB2B0C695600A601BC /* NetImageConfig.m in Sources */,
|
||||||
8C9C84892B0D286F00A601BC /* Api+Gift.m in Sources */,
|
8C9C84892B0D286F00A601BC /* Api+Gift.m in Sources */,
|
||||||
@@ -2305,6 +2316,7 @@
|
|||||||
8C9C841F2B0C697A00A601BC /* StageView.m in Sources */,
|
8C9C841F2B0C697A00A601BC /* StageView.m in Sources */,
|
||||||
8C9C844D2B0C697A00A601BC /* LoginForgetPasswordPresent.m in Sources */,
|
8C9C844D2B0C697A00A601BC /* LoginForgetPasswordPresent.m in Sources */,
|
||||||
8C9C82C12B0C695600A601BC /* Api.m in Sources */,
|
8C9C82C12B0C695600A601BC /* Api.m in Sources */,
|
||||||
|
23270C2C2B0E041300B9303B /* MessageAudioCenter.m in Sources */,
|
||||||
8C9C844A2B0C697A00A601BC /* Api+Mine.m in Sources */,
|
8C9C844A2B0C697A00A601BC /* Api+Mine.m in Sources */,
|
||||||
8C9C82A82B0C695600A601BC /* BaseViewController.m in Sources */,
|
8C9C82A82B0C695600A601BC /* BaseViewController.m in Sources */,
|
||||||
8C9C82C72B0C695600A601BC /* NSMutableDictionary+Safe.m in Sources */,
|
8C9C82C72B0C695600A601BC /* NSMutableDictionary+Safe.m in Sources */,
|
||||||
|
@@ -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
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 142 B |
Binary file not shown.
After Width: | Height: | Size: 231 B |
@@ -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
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 281 B |
Binary file not shown.
After Width: | Height: | Size: 433 B |
@@ -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
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 387 B |
Binary file not shown.
After Width: | Height: | Size: 674 B |
@@ -68,13 +68,18 @@
|
|||||||
- (void)loadSessionData {
|
- (void)loadSessionData {
|
||||||
NSArray<NIMRecentSession *> *allRecentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy];
|
NSArray<NIMRecentSession *> *allRecentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy];
|
||||||
__block int unreadCount = 0;
|
__block int unreadCount = 0;
|
||||||
|
NSArray *getList ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NSMutableArray* sessionList = [NSMutableArray array];
|
NSMutableArray* sessionList = [NSMutableArray array];
|
||||||
[allRecentSessions enumerateObjectsUsingBlock:^(NIMRecentSession * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
[allRecentSessions enumerateObjectsUsingBlock:^(NIMRecentSession * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||||
if (![[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:obj.session.sessionId]) {
|
if ([[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:obj.session.sessionId] || [[ClientConfig shareConfig].configInfo.officialAccountUids containsObject:obj.session.sessionId]) {
|
||||||
if (obj.session.sessionId.integerValue > 0) {
|
return;
|
||||||
[sessionList addObject:obj];
|
}
|
||||||
unreadCount += obj.unreadCount;
|
if (obj.session.sessionId.integerValue > 0 ) {
|
||||||
}
|
[sessionList addObject:obj];
|
||||||
|
unreadCount += obj.unreadCount;
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -105,7 +110,7 @@
|
|||||||
/// 增加最近会话完成
|
/// 增加最近会话完成
|
||||||
- (void)didAddRecentSession:(NIMRecentSession *)recentSession totalUnreadCount:(NSInteger)totalUnreadCount {
|
- (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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +139,7 @@
|
|||||||
/// 最近会话修改完成
|
/// 最近会话修改完成
|
||||||
- (void)didUpdateRecentSession:(NIMRecentSession *)recentSession totalUnreadCount:(NSInteger)totalUnreadCount {
|
- (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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// MessageAudioCenter.h
|
||||||
|
// xplan-ios
|
||||||
|
//
|
||||||
|
// Created by 冯硕 on 2022/4/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
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
|
@@ -0,0 +1,74 @@
|
|||||||
|
//
|
||||||
|
// MessageAudioCenter.m
|
||||||
|
// xplan-ios
|
||||||
|
//
|
||||||
|
// Created by 冯硕 on 2022/4/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "MessageAudioCenter.h"
|
||||||
|
#import <NIMSDK/NIMSDK.h>
|
||||||
|
|
||||||
|
@interface MessageAudioCenter ()<NIMMediaManagerDelegate>
|
||||||
|
@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
|
@@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// MessageConentAudioView.h
|
||||||
|
// xplan-ios
|
||||||
|
//
|
||||||
|
// Created by 冯硕 on 2022/4/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "MessageContentProtocol.h"
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface MessageConentAudioView : UIView<MessageContentProtocol>
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
@@ -0,0 +1,158 @@
|
|||||||
|
//
|
||||||
|
// MessageConentAudioView.m
|
||||||
|
// xplan-ios
|
||||||
|
//
|
||||||
|
// Created by 冯硕 on 2022/4/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "MessageConentAudioView.h"
|
||||||
|
///Third
|
||||||
|
#import <Masonry/Masonry.h>
|
||||||
|
#import <NIMSDK/NIMSDK.h>
|
||||||
|
///Tool
|
||||||
|
#import "ThemeColor.h"
|
||||||
|
#import "MessageAudioCenter.h"
|
||||||
|
@interface MessageConentAudioView ()<NIMMediaManagerDelegate>
|
||||||
|
///背景
|
||||||
|
@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
|
Reference in New Issue
Block a user