| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- //
- // UITableViewController.m
- // chatandvideotest
- //
- // Created by Dongke on 15/11/18.
- // Copyright © 2015年 dongke. All rights reserved.
- //
- #import "DKUITableViewController.h"
- #import <MobileCoreServices/MobileCoreServices.h>
- #import "DKAudioPlayerHelper.h"
- @interface DKUITableViewController()<DKMessageInputViewDelegate>
- @property (nonatomic, strong) DKUITableViewCell *currentSelectedCell;
- /**
- * 判断是否用户手指滚动
- */
- @property (nonatomic, assign) BOOL isUserScrolling;
- @property (nonatomic, weak, readwrite) DKMessageInputView *messageInputView;
- @property (nonatomic, strong, readwrite) DKVoiceRecordHUD *voiceRecordHUD;
- /**
- * 管理录音工具对象
- */
- @property (nonatomic, strong) DKVoiceRecordHelper *voiceRecordHelper;
- /**
- * 判断是不是超出了录音最大时长
- */
- @property (nonatomic) BOOL isMaxTimeStop;
- #pragma mark - DataSource Change
- /**
- * 改变数据源需要的子线程
- *
- * @param queue 子线程执行完成的回调block
- */
- - (void)exChangeMessageDataSourceQueue:(void (^)())queue;
- /**
- * 执行块代码在主线程
- *
- * @param queue 主线程执行完成回调block
- */
- - (void)exMainQueue:(void (^)())queue;
- #pragma mark - Life Cycle
- /**
- * 配置默认参数
- */
- - (void)setup;
- /**
- * 初始化显示控件
- */
- - (void)initilzer;
- #pragma mark - RecorderPath Helper Method
- /**
- * 获取录音的路径
- *
- * @return 返回录音的路径
- */
- - (NSString *)getRecorderPath;
- #pragma mark - UITextView Helper Method
- #pragma mark - Scroll Message TableView Helper Method
- /**
- * 根据bottom的数值配置消息列表的内部布局变化
- *
- * @param bottom 底部的空缺高度
- */
- - (void)setTableViewInsetsWithBottomValue:(CGFloat)bottom;
- /**
- * 根据底部高度获取UIEdgeInsets常量
- *
- * @param bottom 底部高度
- *
- * @return 返回UIEdgeInsets常量
- */
- - (UIEdgeInsets)tableViewInsetsWithBottomValue:(CGFloat)bottom;
- #pragma mark - Message Calculate Cell Height
- /**
- * 统一计算Cell的高度方法
- *
- * @param message 被计算目标消息对象
- * @param indexPath 被计算目标消息所在的位置
- *
- * @return 返回计算的高度
- */
- - (CGFloat)calculateCellHeightWithMessage:(id <DKMessageModel>)message atIndexPath:(NSIndexPath *)indexPath;
- #pragma mark - Message Send helper Method
- /**
- * 根据录音路径开始发送语音消息
- *
- * @param voicePath 目标语音路径
- * @param voiceDuration 目标语音时长
- */
- - (void)didSendMessageWithVoice:(NSString *)voicePath voiceDuration:(NSString*)voiceDuration;
- #pragma mark - Voice Recording Helper Method
- /**
- * 开始录音
- */
- - (void)startRecord;
- /**
- * 完成录音
- */
- - (void)finishRecorded;
- /**
- * 想停止录音
- */
- - (void)pauseRecord;
- /**
- * 继续录音
- */
- - (void)resumeRecord;
- /**
- * 取消录音
- */
- - (void)cancelRecord;
- @end
- @implementation DKUITableViewController
- #pragma mark - DataSource Change
- - (void)exChangeMessageDataSourceQueue:(void (^)())queue {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), queue);
- }
- - (void)exMainQueue:(void (^)())queue {
- dispatch_async(dispatch_get_main_queue(), queue);
- }
- - (void)addMessage:(DKMessage *)addedMessage {
- WEAKSELF
- [self exChangeMessageDataSourceQueue:^{
- NSMutableArray *messages = [NSMutableArray arrayWithArray:weakSelf.messages];
- [messages addObject:addedMessage];
-
- NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:1];
- [indexPaths addObject:[NSIndexPath indexPathForRow:messages.count - 1 inSection:0]];
-
- [weakSelf exMainQueue:^{
- weakSelf.messages = messages;
- [weakSelf.messageTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
- [weakSelf scrollToBottomAnimated:YES];
- }];
- }];
- }
- #pragma mark - Propertys
- - (NSMutableArray *)messages {
- if (!_messages) {
- _messages = [[NSMutableArray alloc] initWithCapacity:0];
- }
- return _messages;
- }
- - (DKVoiceRecordHUD *)voiceRecordHUD {
- if (!_voiceRecordHUD) {
- _voiceRecordHUD = [[DKVoiceRecordHUD alloc] initWithFrame:CGRectMake(0, 0, 140, 140)];
- }
- return _voiceRecordHUD;
- }
- - (DKVoiceRecordHelper *)voiceRecordHelper {
- if (!_voiceRecordHelper) {
- _isMaxTimeStop = NO;
-
- WEAKSELF
- _voiceRecordHelper = [[DKVoiceRecordHelper alloc] init];
- _voiceRecordHelper.maxTimeStopRecorderCompletion = ^{
- DLog(@"已经达到最大限制时间了,进入下一步的提示");
-
- // Unselect and unhilight the hold down button, and set isMaxTimeStop to YES.
- UIButton *holdDown = weakSelf.messageInputView.holdDownButton;
- holdDown.selected = NO;
- holdDown.highlighted = NO;
- weakSelf.isMaxTimeStop = YES;
-
- [weakSelf finishRecorded];
- };
- _voiceRecordHelper.peakPowerForChannel = ^(float peakPowerForChannel) {
- weakSelf.voiceRecordHUD.peakPower = peakPowerForChannel;
- };
- _voiceRecordHelper.maxRecordTime = kVoiceRecorderTotalTime;
- }
- return _voiceRecordHelper;
- }
- #pragma mark - Messages View Controller
- - (void)setBackgroundColor:(UIColor *)color {
- self.view.backgroundColor = color;
- _messageTableView.backgroundColor = color;
- }
- - (void)setBackgroundImage:(UIImage *)backgroundImage {
- self.messageTableView.backgroundView = nil;
- self.messageTableView.backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
- }
- - (void)scrollToBottomAnimated:(BOOL)animated {
- // if (![self shouldAllowScroll])
- // return;
-
- NSInteger rows = [self.messageTableView numberOfRowsInSection:0];
-
- if (rows > 0) {
- [self.messageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:rows - 1 inSection:0]
- atScrollPosition:UITableViewScrollPositionBottom
- animated:animated];
- }
- }
- - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
- atScrollPosition:(UITableViewScrollPosition)position
- animated:(BOOL)animated {
- // if (![self shouldAllowScroll])
- // return;
-
- [self.messageTableView scrollToRowAtIndexPath:indexPath
- atScrollPosition:position
- animated:animated];
- }
- #pragma mark - Previte Method
- #pragma mark - Life Cycle
- - (void)setup {
- //self.keyboardViewHeight = (kIsiPad ? 264 : 216);
- _allowsPanToDismissKeyboard = NO;
- _allowsSendVoice = YES;
- _inputViewStyle = DKMessageInputViewStyleFlat;
-
- self.delegate = self;
- self.dataSource = self;
- }
- - (id)init {
- self = [super init];
- if (self) {
- [self setup];
- }
- return self;
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- [self setup];
- }
- - (void)initilzer {
- if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
-
- if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
- self.edgesForExtendedLayout = UIRectEdgeNone;
- }
-
- // 默认设置用户滚动为NO
- _isUserScrolling = NO;
-
- // // 初始化message tableView
- // DKMessageTableView *messageTableView = [[DKMessageTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
- // messageTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- // messageTableView.dataSource = self;
- // messageTableView.delegate = self;
- // messageTableView.separatorColor = [UIColor clearColor];
- // messageTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- //
- //
- // [self.view addSubview:messageTableView];
- // [self.view sendSubviewToBack:messageTableView];
- // _messageTableView = messageTableView;
-
- // 设置Message TableView 的bottom edg
- CGFloat inputViewHeight = (self.inputViewStyle == DKMessageInputViewStyleFlat) ? 45.0f : 40.0f;
- [self setTableViewInsetsWithBottomValue:inputViewHeight];
-
- // 设置整体背景颜色
- [self setBackgroundColor:[UIColor whiteColor]];
-
- // 输入工具条的frame
- CGRect inputFrame = CGRectMake(0.0f,
- self.view.frame.size.height - inputViewHeight,
- self.view.frame.size.width,
- inputViewHeight);
-
- WEAKSELF
- if (self.allowsPanToDismissKeyboard) {
- // 控制输入工具条的位置块
- void (^AnimationForMessageInputViewAtPoint)(CGPoint point) = ^(CGPoint point) {
-
- CGRect inputViewFrame = weakSelf.messageInputView.frame;
- CGPoint keyboardOrigin = [weakSelf.view convertPoint:point fromView:nil];
- inputViewFrame.origin.y = keyboardOrigin.y - inputViewFrame.size.height;
- weakSelf.messageInputView.frame = inputViewFrame;
- };
-
- }
-
-
- // 初始化输入工具条
- DKMessageInputView *inputView = [[DKMessageInputView alloc] initWithFrame:inputFrame];
- //inputView.allowsSendFace = self.allowsSendFace;
- inputView.allowsSendVoice = self.allowsSendVoice;
- //inputView.allowsSendMultiMedia = self.allowsSendMultiMedia;
- inputView.delegate = self;
- [self.view addSubview:inputView];
- [self.view bringSubviewToFront:inputView];
-
- _messageInputView = inputView;
-
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- // 设置键盘通知或者手势控制键盘消失
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- if (self.textViewInputViewType != DKInputViewTypeNormal) {
- [self layoutOtherMenuViewHiden:YES];
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- // 初始化消息页面布局
- [self initilzer];
- [[DKMessageBubbleView appearance] setFont:[UIFont systemFontOfSize:16.0f]];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)dealloc {
- _messages = nil;
- //_delegate = nil;
- _dataSource = nil;
- _messageTableView.delegate = nil;
- _messageTableView.dataSource = nil;
- _messageTableView = nil;
- _messageInputView = nil;
-
- }
- #pragma mark - View Rotation
- - (BOOL)shouldAutorotate {
- return NO;
- }
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
- - (NSUInteger)supportedInterfaceOrientations
- #else
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations
- #endif
- {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- return UIInterfaceOrientationPortrait;
- }
- #pragma mark - RecorderPath Helper Method
- - (NSString *)getRecorderPath {
- NSString *recorderPath = nil;
- recorderPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
- NSDate *now = [NSDate date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyyMMddHHmmssSSS"];
- recorderPath = [recorderPath stringByAppendingFormat:@"%@-MySound.aac", [dateFormatter stringFromDate:now]];
- return recorderPath;
- }
- #pragma mark - Scroll Message TableView Helper Method
- - (void)setTableViewInsetsWithBottomValue:(CGFloat)bottom {
- UIEdgeInsets insets = [self tableViewInsetsWithBottomValue:bottom];
- self.messageTableView.contentInset = insets;
- self.messageTableView.scrollIndicatorInsets = insets;
- }
- - (UIEdgeInsets)tableViewInsetsWithBottomValue:(CGFloat)bottom {
- UIEdgeInsets insets = UIEdgeInsetsZero;
-
- if ([self respondsToSelector:@selector(topLayoutGuide)]) {
- insets.top = 2;//self.topLayoutGuide.length;
- }
-
- insets.bottom = bottom;
-
- return insets;
- }
- #pragma mark - Message Calculate Cell Height
- - (CGFloat)calculateCellHeightWithMessage:(id <DKMessageModel>)message atIndexPath:(NSIndexPath *)indexPath {
- CGFloat cellHeight = 0;
-
-
- cellHeight = [DKUITableViewCell calculateCellHeightWithMessage:message displaysTimestamp:NO];
-
- return cellHeight;
- }
- #pragma mark - Message Send helper Method
- - (void)didSendMessageWithVoice:(NSString *)voicePath voiceDuration:(NSString*)voiceDuration {
- DLog(@"send voicePath : %@", voicePath);
- if ([self.delegate respondsToSelector:@selector(didSendVoice:voiceDuration:fromSender:onDate:)]) {
- [self.delegate didSendVoice:voicePath voiceDuration:voiceDuration fromSender:self.messageSender onDate:[NSDate date]];
- }
- }
- #pragma mark - Other Menu View Frame Helper Mehtod
- - (void)layoutOtherMenuViewHiden:(BOOL)hide {
- // [self.messageInputView.inputTextView resignFirstResponder];
- [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- __block CGRect inputViewFrame = self.messageInputView.frame;
- __block CGRect otherMenuViewFrame;
-
- void (^InputViewAnimation)(BOOL hide) = ^(BOOL hide) {
- inputViewFrame.origin.y = (hide ? (CGRectGetHeight(self.view.bounds) - CGRectGetHeight(inputViewFrame)) : (CGRectGetMinY(otherMenuViewFrame) - CGRectGetHeight(inputViewFrame)));
- self.messageInputView.frame = inputViewFrame;
- };
-
-
-
- InputViewAnimation(hide);
-
- [self setTableViewInsetsWithBottomValue:self.view.frame.size.height
- - self.messageInputView.frame.origin.y];
-
- [self scrollToBottomAnimated:NO];
- } completion:^(BOOL finished) {
-
- }];
- }
- #pragma mark - Voice Recording Helper Method
- - (void)prepareRecordWithCompletion:(DKPrepareRecorderCompletion)completion {
- [self.voiceRecordHelper prepareRecordingWithPath:[self getRecorderPath] prepareRecorderCompletion:completion];
- }
- - (void)startRecord {
- [self.voiceRecordHUD startRecordingHUDAtView:self.view];
- [self.voiceRecordHelper startRecordingWithStartRecorderCompletion:^{
- }];
- }
- - (void)finishRecorded {
- WEAKSELF
- [self.voiceRecordHUD stopRecordCompled:^(BOOL fnished) {
- weakSelf.voiceRecordHUD = nil;
- }];
- [self.voiceRecordHelper stopRecordingWithStopRecorderCompletion:^{
- [weakSelf didSendMessageWithVoice:weakSelf.voiceRecordHelper.recordPath voiceDuration:weakSelf.voiceRecordHelper.recordDuration];
- }];
- }
- - (void)pauseRecord {
- [self.voiceRecordHUD pauseRecord];
- }
- - (void)resumeRecord {
- [self.voiceRecordHUD resaueRecord];
- }
- - (void)cancelRecord {
- WEAKSELF
- [self.voiceRecordHUD cancelRecordCompled:^(BOOL fnished) {
- weakSelf.voiceRecordHUD = nil;
- }];
- [self.voiceRecordHelper cancelledDeleteWithCompletion:^{
-
- }];
- }
- #pragma mark - DKMessageInputView Delegate
- - (void)didChangeSendVoiceAction:(BOOL)changed {
- if (changed) {
- if (self.textViewInputViewType == DKInputViewTypeText)
- return;
- // 在这之前,textViewInputViewType已经不是DKTextViewTextInputType
- [self layoutOtherMenuViewHiden:YES];
- }
- }
- - (void)didCamera:(BOOL)flg {
- if ([self.delegate respondsToSelector:@selector(didCameraAction:)]) {
- [self.delegate didCameraAction:flg];
- }
- }
- - (void)didPhoto:(BOOL)flg {
- if ([self.delegate respondsToSelector:@selector(didPhotoAction:)]) {
- [self.delegate didPhotoAction:flg];
- }
-
- }
- - (void)didPosition:(BOOL)flg {
- if ([self.delegate respondsToSelector:@selector(didPostionAction:)]) {
- [self.delegate didPostionAction:flg];
- }
- }
- - (void)prepareRecordingVoiceActionWithCompletion:(BOOL (^)(void))completion {
- DLog(@"prepareRecordingWithCompletion");
- [self prepareRecordWithCompletion:completion];
- }
- - (void)didStartRecordingVoiceAction {
- DLog(@"didStartRecordingVoice");
- [self startRecord];
- }
- - (void)didCancelRecordingVoiceAction {
- DLog(@"didCancelRecordingVoice");
- [self cancelRecord];
- }
- - (void)didFinishRecoingVoiceAction {
- DLog(@"didFinishRecoingVoice");
- if (self.isMaxTimeStop == NO) {
- [self finishRecorded];
- } else {
- self.isMaxTimeStop = NO;
- }
- }
- - (void)didDragOutsideAction {
- DLog(@"didDragOutsideAction");
- [self resumeRecord];
- }
- - (void)didDragInsideAction {
- DLog(@"didDragInsideAction");
- [self pauseRecord];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- self.isUserScrolling = YES;
-
- UIMenuController *menu = [UIMenuController sharedMenuController];
- if (menu.isMenuVisible) {
- [menu setMenuVisible:NO animated:YES];
- }
-
- if (self.textViewInputViewType != DKInputViewTypeNormal) {
- [self layoutOtherMenuViewHiden:YES];
- }
- }
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
- self.isUserScrolling = NO;
- }
- #pragma mark - DKMessageTableViewController Delegate
- - (BOOL)shouldPreventScrollToBottomWhileUserScrolling {
- return YES;
- }
- #pragma mark - DKMessageTableViewController DataSource
- - (id <DKMessageModel>)messageForRowAtIndexPath:(NSIndexPath *)indexPath {
- return self.messages[indexPath.row];
- }
- #pragma mark - Table View Data Source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.messages.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- id <DKMessageModel> message = [self.dataSource messageForRowAtIndexPath:indexPath];
-
- // 如果需要定制复杂的业务UI,那么就实现该DataSource方法
- if ([self.dataSource respondsToSelector:@selector(tableView:cellForRowAtIndexPath:targetMessage:)]) {
- UITableViewCell *tableViewCell = [self.dataSource tableView:tableView cellForRowAtIndexPath:indexPath targetMessage:message];
- return tableViewCell;
- }
-
- BOOL displayTimestamp = NO;
-
-
- static NSString *cellIdentifier = @"DKUITableViewCell";
-
- DKUITableViewCell *messageTableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
-
- if (!messageTableViewCell) {
- messageTableViewCell = [[DKUITableViewCell alloc] initWithMessage:message displaysTimestamp:displayTimestamp reuseIdentifier:cellIdentifier];
- messageTableViewCell.delegate = self;
- }
-
- messageTableViewCell.indexPath = indexPath;
- [messageTableViewCell configureCellWithMessage:message displaysTimestamp:displayTimestamp];
- [messageTableViewCell setBackgroundColor:tableView.backgroundColor];
-
-
- return messageTableViewCell;
- }
- #pragma mark - Table View Delegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- id <DKMessageModel> messageModel = [self.dataSource messageForRowAtIndexPath:indexPath];
-
- CGFloat calculateCellHeight ;
-
- if ([self.delegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:targetMessage:)]) {
- calculateCellHeight = [self.delegate tableView:tableView heightForRowAtIndexPath:indexPath targetMessage:messageModel];
-
- //return calculateCellHeight;
- } else {
- calculateCellHeight = [self calculateCellHeightWithMessage:messageModel atIndexPath:indexPath];
- }
-
- return calculateCellHeight;
- }
- ////////////////-----------
- #pragma mark - DKMessageTableViewCell delegate
- - (void)multiMediaMessageDidSelectedOnMessage:(id<DKMessageModel>)message atIndexPath:(NSIndexPath *)indexPath onMessageTableViewCell:(DKUITableViewCell *)messageTableViewCell {
- UIViewController *disPlayViewController;
- switch (message.messageMediaType) {
-
- case DKBubbleMessageMediaTypeVoice: {
- DLog(@"message : %@", message.voicePath);
-
- // Mark the voice as read and hide the red dot.
- message.isRead = YES;
- messageTableViewCell.messageBubbleView.voiceUnreadDotImageView.hidden = YES;
-
- [[DKAudioPlayerHelper shareInstance] setDelegate:(id<NSFileManagerDelegate>)self];
- if (_currentSelectedCell) {
- [_currentSelectedCell.messageBubbleView.animationVoiceImageView stopAnimating];
- }
- if (_currentSelectedCell == messageTableViewCell) {
- [messageTableViewCell.messageBubbleView.animationVoiceImageView stopAnimating];
- [[DKAudioPlayerHelper shareInstance] stopAudio];
- self.currentSelectedCell = nil;
- } else {
- self.currentSelectedCell = messageTableViewCell;
- [messageTableViewCell.messageBubbleView.animationVoiceImageView startAnimating];
- [[DKAudioPlayerHelper shareInstance] managerAudioWithFileName:message.voicePath toPlay:YES];
- }
- break;
- }
- default:
- break;
- }
- if (disPlayViewController) {
- [self.navigationController pushViewController:disPlayViewController animated:YES];
- }
- }
- #pragma mark - DKAudioPlayerHelper Delegate
- - (void)didAudioPlayerStopPlay:(AVAudioPlayer *)audioPlayer {
- if (!_currentSelectedCell) {
- return;
- }
- [_currentSelectedCell.messageBubbleView.animationVoiceImageView stopAnimating];
- self.currentSelectedCell = nil;
- }
- #pragma mark - DKMessageTableViewController Delegate
- /**
- * 发送语音消息的回调方法
- *
- * @param voicePath 目标语音本地路径
- * @param voiceDuration 目标语音时长
- * @param sender 发送者的名字
- * @param date 发送时间
- */
- - (void)didSendVoice:(NSString *)voicePath voiceDuration:(NSString *)voiceDuration fromSender:(NSString *)sender onDate:(NSDate *)date {
- DKMessage *voiceMessage = [[DKMessage alloc] initWithVoicePath:voicePath voiceUrl:nil voiceDuration:voiceDuration sender:sender timestamp:date];
- // voiceMessage.avatar = [UIImage imageNamed:@"avatar"];
- // voiceMessage.avatarUrl = @"http://www.pailixiu.com/jack/meIcon@2x.png";
- //voiceMessage.bubbleMessageType=DKBubbleMessageTypeSending;
- [self addMessage:voiceMessage];
- //[self finishSendMessageWithBubbleMessageType:DKBubbleMessageMediaTypeVoice];
- }
- @end
|