1212#import " ContactViewController.h"
1313#import " NIMKitLocationPoint.h"
1414#import < AVFoundation/AVFoundation.h>
15+ // #import "NIMKitMediaFetcher.h"
16+
1517#define NTESNotifyID @" id"
1618#define NTESCustomContent @" content"
1719
@@ -28,6 +30,7 @@ @interface ConversationViewController ()<NIMMediaManagerDelegate,NIMMediaManager
2830}
2931@property (nonatomic ,strong ) AVAudioPlayer *player; // 播放提示音
3032@property (nonatomic ,strong ) AVAudioPlayer *redPacketPlayer; // 播放提示音
33+ // @property (nonatomic,strong) NIMKitMediaFetcher *mediaFetcher;
3134
3235@end
3336
@@ -63,6 +66,14 @@ - (instancetype)init {
6366 return self;
6467}
6568
69+ // - (NIMKitMediaFetcher *)mediaFetcher
70+ // {
71+ // if (!_mediaFetcher) {
72+ // _mediaFetcher = [[NIMKitMediaFetcher alloc] init];
73+ // }
74+ // return _mediaFetcher;
75+ // }
76+
6677-(void )startSession : (NSString *)sessionID withType : (NSString *)type {
6778 _sessionID = sessionID;
6879 _type = type;
@@ -204,13 +215,18 @@ -(NSMutableArray *)setTimeArr:(NSArray *)messageArr{
204215 [dic setObject: @" video" forKey: @" msgType" ];
205216 NIMVideoObject *object = message.messageObject ;
206217
207- [dic setObject: [NSString stringWithFormat: @" %@ " ,object.url ] forKey: @" url " ];
218+ [dic setObject: [NSString stringWithFormat: @" %@ " ,object.url ] forKey: @" videoUrl " ];
208219 [dic setObject: [NSString stringWithFormat: @" %@ " , object.displayName ] forKey: @" displayName" ];
209220 [dic setObject: [NSString stringWithFormat: @" %@ " , object.coverUrl ] forKey: @" coverUrl" ];
210221 [dic setObject: [NSString stringWithFormat: @" %f " ,object.coverSize.height ] forKey: @" coverSizeHeight" ];
211222 [dic setObject: [NSString stringWithFormat: @" %f " , object.coverSize.width ] forKey: @" coverSizeWidth" ];
212223 [dic setObject: [NSString stringWithFormat: @" %ld " ,object.duration ] forKey: @" duration" ];
213224 [dic setObject: [NSString stringWithFormat: @" %lld " ,object.fileLength] forKey: @" fileLength" ];
225+ NSMutableDictionary *videoObj = [NSMutableDictionary dictionary ];
226+ [videoObj setObject: [NSString stringWithFormat: @" %@ " ,object.url ] forKey: @" videoUrl" ];
227+ [videoObj setObject: [NSString stringWithFormat: @" %@ " , object.coverUrl ] forKey: @" coverUrl" ];
228+ [dic setObject: videoObj forKey: @" extend" ];
229+ /*
214230 if([[NSFileManager defaultManager] fileExistsAtPath:object.coverPath]){
215231 [dic setObject:[NSString stringWithFormat:@"%@",object.coverPath] forKey:@"coverPath"];
216232 }else{
@@ -220,7 +236,7 @@ -(NSMutableArray *)setTimeArr:(NSArray *)messageArr{
220236 [dic setObject:[NSString stringWithFormat:@"%@",object.coverPath] forKey:@"coverPath"];
221237 }
222238 }];
223- }
239+ }*/
224240 if ([[NSFileManager defaultManager ] fileExistsAtPath: object.path]) {
225241 [dic setObject: [NSString stringWithFormat: @" %@ " ,object.path] forKey: @" mediaPath" ];
226242 }else {
@@ -230,7 +246,7 @@ -(NSMutableArray *)setTimeArr:(NSArray *)messageArr{
230246 [dic setObject: [NSString stringWithFormat: @" %@ " ,object.path] forKey: @" mediaPath" ];
231247 }
232248 } progress: ^(float progress) {
233- NSLog (@" 下载进度 %. f" ,progress);
249+ NSLog (@" 视频下载进度 % f" ,progress);
234250 }];
235251 }
236252 }else if (message.messageType == NIMMessageTypeLocation){
@@ -409,18 +425,22 @@ -(void)sendImageMessages:( NSString *)path displayName:( NSString *)displayNa
409425}
410426
411427// 发送视频
412- -(void )sendTextMessage : ( NSString *)path duration : ( NSString *)duration width : ( NSString *)width height : ( NSString *)height displayName : ( NSString *)displayName {
413- NIMMessage *message ;
414- // if ( image) {
415- // message = [NIMMessageMaker msgWithImage:image] ;
416- // }else {
417- message = [NIMMessageMaker msgWithVideo: path andeSession: _session];
418- // }
419- if ([self isFriendToSendMessage: message ]) {
420- [[NIMSDK sharedSDK ].chatManager sendMessage: message toSession: _session error: nil ];
428+ -(void )sendVideoMessage : ( NSString *)path duration : ( NSString *)duration width : ( NSString *)width height : ( NSString *)height displayName : ( NSString *)displayName {
429+ // __weak typeof(self) weakSelf = self ;
430+ // [self.mediaFetcher fetchMediaFromCamera:^(NSString *path, UIImage * image) {
431+ NIMMessage * message;
432+ // if (image) {
433+ // message = [NIMMessageMaker msgWithImage:image andeSession:_session];
434+ // }else{
435+ if ([path hasPrefix: @" file:///private " ]) {
436+ path = [path stringByReplacingOccurrencesOfString: @" file:///private " withString: @" " ];
421437 }
422- [[NIMSDK sharedSDK ].chatManager sendMessage: message toSession: _session error: nil ];
423-
438+ message = [NIMMessageMaker msgWithVideo: path andeSession: _session];
439+ // }
440+ if ([self isFriendToSendMessage: message]) {
441+ [[NIMSDK sharedSDK ].chatManager sendMessage: message toSession: _session error: nil ];
442+ }
443+ // }];
424444}
425445
426446// 发送自定义消息
@@ -882,13 +902,18 @@ -(void)refrashMessage:(NIMMessage *)message From:(NSString *)from {
882902 [dic2 setObject: @" video" forKey: @" msgType" ];
883903 NIMVideoObject *object = message.messageObject ;
884904
885- [dic2 setObject: [NSString stringWithFormat: @" %@ " ,object.url ] forKey: @" url " ];
905+ [dic2 setObject: [NSString stringWithFormat: @" %@ " ,object.url ] forKey: @" videoUrl " ];
886906 [dic2 setObject: [NSString stringWithFormat: @" %@ " , object.displayName ] forKey: @" displayName" ];
887907 [dic2 setObject: [NSString stringWithFormat: @" %@ " , object.coverUrl ] forKey: @" coverUrl" ];
888908 [dic2 setObject: [NSString stringWithFormat: @" %f " ,object.coverSize.height ] forKey: @" coverSizeHeight" ];
889909 [dic2 setObject: [NSString stringWithFormat: @" %f " , object.coverSize.width ] forKey: @" coverSizeWidth" ];
890910 [dic2 setObject: [NSString stringWithFormat: @" %ld " ,object.duration ] forKey: @" duration" ];
891911 [dic2 setObject: [NSString stringWithFormat: @" %lld " ,object.fileLength] forKey: @" fileLength" ];
912+ NSMutableDictionary *videoObj = [NSMutableDictionary dictionary ];
913+ [videoObj setObject: [NSString stringWithFormat: @" %@ " ,object.url ] forKey: @" videoUrl" ];
914+ [videoObj setObject: [NSString stringWithFormat: @" %@ " , object.coverUrl ] forKey: @" coverUrl" ];
915+ [dic2 setObject: videoObj forKey: @" extend" ];
916+ /*
892917 if([[NSFileManager defaultManager] fileExistsAtPath:object.coverPath]){
893918 [dic2 setObject:[NSString stringWithFormat:@"%@",object.coverPath] forKey:@"coverPath"];
894919 }else{
@@ -898,17 +923,20 @@ -(void)refrashMessage:(NIMMessage *)message From:(NSString *)from {
898923 [dic2 setObject:[NSString stringWithFormat:@"%@",object.coverPath] forKey:@"coverPath"];
899924 }
900925 }];
901- }
926+ }*/
902927 if ([[NSFileManager defaultManager ] fileExistsAtPath: object.path]) {
903928 [dic2 setObject: [NSString stringWithFormat: @" %@ " ,object.path] forKey: @" mediaPath" ];
904929 }else {
905930
906931 [[NIMObject initNIMObject ] downLoadVideo: object Error: ^(NSError *error) {
907932 if (!error) {
908933 [dic2 setObject: [NSString stringWithFormat: @" %@ " ,object.path] forKey: @" mediaPath" ];
934+ NSLog (@" --------下载完成~!!!dic2:%@ " ,dic2);
935+ NIMModel *model = [NIMModel initShareMD ];
936+ model.videoProgress = [NSMutableArray arrayWithObjects: dic2, nil ];
909937 }
910938 } progress: ^(float progress) {
911- NSLog (@" 下载进度%.f " ,progress);
939+ NSLog (@" ---------- 下载进度%f dic2: %@ " ,progress,dic2 );
912940 }];
913941 }
914942 }else if (message.messageType == NIMMessageTypeLocation){
0 commit comments