@@ -27,6 +27,7 @@ @interface ConversationViewController ()<NIMMediaManagerDelegate,NIMMediaManager
2727
2828}
2929@property (nonatomic ,strong ) AVAudioPlayer *player; // 播放提示音
30+ @property (nonatomic ,strong ) AVAudioPlayer *redPacketPlayer; // 播放提示音
3031
3132@end
3233
@@ -53,6 +54,8 @@ - (instancetype)init {
5354 if (self) {
5455 NSURL *url = [[NSBundle mainBundle ] URLForResource: @" message" withExtension: @" wav" ];
5556 _player = [[AVAudioPlayer alloc ] initWithContentsOfURL: url error: nil ];
57+ NSURL *redPackUrl = [[NSBundle mainBundle ] URLForResource: @" packet_tip" withExtension: @" wav" ];
58+ _redPacketPlayer = [[AVAudioPlayer alloc ] initWithContentsOfURL: redPackUrl error: nil ];
5659 }
5760 return self;
5861}
@@ -549,7 +552,15 @@ - (void)playTipsMusicWithMessage:(NIMMessage *)message{
549552 if (message.messageType == 100 ) {
550553 NIMCustomObject *customObject = message.messageObject ;
551554 DWCustomAttachment *obj = customObject.attachment ;
552- if (obj.custType == CustomMessgeTypeRedPacketOpenMessage) return ;
555+ if (obj.custType == CustomMessgeTypeRedPacketOpenMessage){
556+ return ;
557+ }else if (obj.custType == CustomMessgeTypeRedpacket){// 红包消息
558+ [self .player stop ];
559+ [self .redPacketPlayer stop ];
560+ [[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryAmbient error: nil ];
561+ [self .redPacketPlayer play ];
562+ return ;
563+ }
553564 }
554565 if (message.messageType == NIMMessageTypeNotification) return ;
555566 if (message.session .sessionType == NIMSessionTypeP2P) {// 个人
@@ -563,6 +574,7 @@ - (void)playTipsMusicWithMessage:(NIMMessage *)message{
563574 }
564575 if (needToPlay) {
565576 [self .player stop ];
577+ [self .redPacketPlayer stop ];
566578 [[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryAmbient error: nil ];
567579 [self .player play ];
568580 }
0 commit comments