commentview.m 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. //
  2. // commentview.m
  3. // YBVideo
  4. //
  5. // Created by 王敏欣 on 2017/8/5.
  6. // Copyright © 2017年 cat. All rights reserved.
  7. //
  8. #import "commentview.h"
  9. #import "commentModel.h"
  10. #import "commCell.h"
  11. #import "XHVoiceRecordHUD.h"
  12. #import "XHVoiceRecordHelper.h"
  13. #import "commDetailCell.h"
  14. #import "SelPeopleV.h"
  15. @interface commentview ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,commCellDelegate,UIGestureRecognizerDelegate>
  16. {
  17. int count;//下拉次数
  18. MJRefreshBackNormalFooter *footer;
  19. int ispush;
  20. BOOL isReply;//判断是否是回复
  21. UILabel *tableviewLine;
  22. UIView *tableheader;
  23. CGFloat _oldOffset;
  24. NSIndexPath *_needScorllToIndexPath; //需要滚动到
  25. BOOL _needScroll;
  26. commCell *_currentCell;
  27. BOOL isLandScreen;
  28. }
  29. @property(nonatomic,strong)UILabel *allCommentLabels;//显示全部评论
  30. @property(nonatomic,copy)NSString *videoid;//视频id
  31. @property(nonatomic,strong)UITableView *tableview;
  32. @property(nonatomic,strong)NSMutableArray *itemsarray;//评论列表
  33. //@property(nonatomic,strong)NSMutableArray *modelarray;//评论模型
  34. @property(nonatomic,copy)NSString *parentid;//回复的评论ID
  35. @property(nonatomic,copy)NSString *commentid;//回复的评论commentid
  36. @property(nonatomic,copy)NSString *touid;//回复的评论UID
  37. @property(nonatomic,copy)NSString *hostid;//发布视频的人的id
  38. @property (nonatomic,strong) AVPlayer *voicePlayer;
  39. @property (nonatomic,assign) BOOL isPlaying;
  40. @property (nonatomic,strong) commCell *voiceCell;
  41. @property (nonatomic,strong) commDetailCell *detailVoiceCell;
  42. @property (nonatomic,assign) BOOL isDetailPlay;
  43. //监听播放起状态的监听者
  44. @property (nonatomic ,strong) id playbackTimeObserver;
  45. @end
  46. @implementation commentview
  47. -(void)dealloc{
  48. NSLog(@"dealloc");
  49. }
  50. - (void)reloadCurCell:(commentModel *)model andIndex:(NSIndexPath *)curIndex andReplist:(NSArray *)list needRefresh:(BOOL)needRefresh{
  51. for (int i = 0; i < _itemsarray.count; i++) {
  52. NSMutableDictionary *muDic = _itemsarray[i];
  53. if ([minstr([muDic valueForKey:@"id"]) isEqual:model.parentid]) {
  54. [muDic setObject:list forKey:@"replylist"];
  55. [muDic setObject:model.replys forKey:@"replys"];
  56. // mol.replyList = list;
  57. // NSLog(@"-------%@",mol.replyList);
  58. //// [_modelarray removeObject:mol];
  59. // [_modelarray replaceObjectAtIndex:i withObject:model];
  60. break;
  61. }
  62. }
  63. if (needRefresh) {
  64. [_tableview reloadRowsAtIndexPaths:@[curIndex] withRowAnimation:UITableViewRowAnimationNone];
  65. }
  66. }
  67. //每次点击 获取最新评论列表
  68. -(void)reloaddata:(NSString *)from{
  69. count+=1;
  70. _commentTool.textField.text = @"";
  71. _commentTool.textField.placeholder = YZMsg(@"说点什么吧~");
  72. NSString *url = [NSString stringWithFormat:@"Video.getComments&videoid=%@&p=%d&uid=%@",_videoid,count,[Config getOwnID]];
  73. YBWeakSelf;
  74. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  75. [weakSelf.tableview.mj_header endRefreshing];
  76. if (code == 0) {
  77. //隐藏评论加载中
  78. [PublicView hideCommenting:weakSelf.tableview];
  79. NSDictionary *infoDic = [info firstObject];
  80. NSArray *commentlist = [infoDic valueForKey:@"commentlist"];
  81. int allcomments = [[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"comments"]] intValue];
  82. weakSelf.allCommentLabels.text = [NSString stringWithFormat:@"%d %@",allcomments,YZMsg(@"评论")];
  83. self.talkCount([NSString stringWithFormat:@"%@",[infoDic valueForKey:@"comments"]] );
  84. if (count == 1) {
  85. [_itemsarray removeAllObjects];
  86. }
  87. for (NSDictionary *dic in commentlist) {
  88. NSMutableDictionary *mudic = [dic mutableCopy];
  89. [_itemsarray addObject:mudic];
  90. }
  91. if (_itemsarray.count == 0) {
  92. [PublicView showTextNoData:_tableview text1:@"" text2:YZMsg(@"暂无评论,快来抢沙发吧") centerY:0.8];
  93. }else{
  94. [PublicView hiddenTextNoData:_tableview];
  95. }
  96. if (commentlist.count == 0) {
  97. [weakSelf.tableview.mj_footer endRefreshingWithNoMoreData];
  98. }else{
  99. [weakSelf.tableview.mj_footer endRefreshing];
  100. }
  101. [weakSelf.tableview reloadData];
  102. if (_needScroll) {
  103. _needScroll = NO;
  104. //滚动
  105. if (_itemsarray.count > _needScorllToIndexPath.row) {
  106. [_tableview scrollToRowAtIndexPath:_needScorllToIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
  107. }
  108. }
  109. }else{
  110. [MBProgressHUD showPop:msg];
  111. }
  112. } Fail:^(id fail) {
  113. [weakSelf.tableview.mj_header endRefreshing];
  114. [weakSelf.tableview.mj_footer endRefreshing];
  115. }];
  116. }
  117. -(instancetype)initWithFrame:(CGRect)frame hide:(commectblock)hide andvideoid:(NSString *)videoid andhostid:(NSString *)hostids count:(int)allcomments talkCount:(commectblock)talk detail:(commectblock)detail youke:(commectblock)youkedenglu andFrom:(NSString *)from{
  118. self = [super initWithFrame:frame];
  119. if (self) {
  120. _needScroll = NO;
  121. _needScorllToIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  122. _fromWhere = from;
  123. _oldOffset = 0;
  124. ispush = 0;//判断发消息的时候 数组滚动最上面
  125. count = 0;//上拉加载次数
  126. _parentid = @"0";
  127. _commentid = @"0";
  128. isReply = NO;//判断回复
  129. self.talkCount = talk;
  130. self.hide = hide;//点击隐藏事件
  131. _videoid = videoid;//获取视频id
  132. _hostid = hostids;
  133. _touid = hostids;
  134. _pushDetail = detail;
  135. _youkedenglu = youkedenglu;
  136. _itemsarray = [NSMutableArray array];
  137. // _modelarray = [NSMutableArray array];
  138. tableheader = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height*0.3 , _window_width,50)];
  139. if ([from isEqual:@"消息事件"]) {
  140. tableheader.y = 20+statusbarHeight;
  141. }
  142. tableheader.layer.masksToBounds = YES;
  143. tableheader.layer.cornerRadius = 10;
  144. tableheader.backgroundColor = RGB(245, 245, 245);
  145. //显示评论的数量
  146. _allCommentLabels = [[UILabel alloc]initWithFrame:CGRectMake(20,0,_window_width/2,50)];
  147. _allCommentLabels.textColor = GrayText;
  148. _allCommentLabels.text = [NSString stringWithFormat:@"%d %@",allcomments,YZMsg(@"评论")];
  149. _allCommentLabels.font = [UIFont systemFontOfSize:15];
  150. [tableheader addSubview:_allCommentLabels];
  151. //关闭按钮
  152. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  153. btn.frame = CGRectMake(_window_width - 45,5,40,40);
  154. btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  155. btn.imageEdgeInsets = UIEdgeInsetsMake(12.5,12.5,12.5,12.5);
  156. [btn setImage:[UIImage imageNamed:@"gray_close"] forState:UIControlStateNormal];
  157. [btn addTarget:self action:@selector(hideself) forControlEvents:UIControlEventTouchUpInside];
  158. [tableheader addSubview:btn];
  159. //tableview顶部横线 和 顶部 view分割开
  160. UILabel *liness = [[UILabel alloc]initWithFrame:CGRectMake(0,49,_window_width,1)];
  161. liness.backgroundColor = RGB(235, 235, 235);
  162. [tableheader addSubview:liness];
  163. [self addSubview:tableheader];
  164. UIView *headerBg = [[UIView alloc]init];
  165. headerBg.backgroundColor = tableheader.backgroundColor;
  166. [self addSubview:headerBg];
  167. [self sendSubviewToBack:headerBg];
  168. [headerBg mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.width.centerX.height.equalTo(tableheader);
  170. make.top.equalTo(tableheader.mas_centerY);
  171. }];
  172. CGRect tabFrame ;
  173. if ([from isEqual:@"消息事件"]) {
  174. tabFrame = CGRectMake(0, 20+statusbarHeight+50, _window_width, _window_height-ShowDiff-20-statusbarHeight-50);
  175. }else {
  176. tabFrame = CGRectMake(0, _window_height*0.3+50, _window_width, _window_height*0.7 - 50-ShowDiff-50);
  177. }
  178. _tableview = [[UITableView alloc]initWithFrame:tabFrame];
  179. _tableview.delegate = self;
  180. _tableview.dataSource = self;
  181. _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
  182. _tableview.backgroundColor = UIColor.whiteColor;
  183. _tableview.layer.masksToBounds = YES;
  184. _tableview.showsVerticalScrollIndicator = NO;
  185. _tableview.estimatedRowHeight = 120.0;
  186. _tableview.estimatedSectionHeaderHeight = 0;
  187. _tableview.estimatedSectionFooterHeight = 0;
  188. // _tableview.layer.masksToBounds = YES;
  189. // _tableview.layer.cornerRadius = 10;
  190. UIView *spaceView = [[UIView alloc]initWithFrame:CGRectMake(0, _tableview.bottom-12, _window_width, 15)];
  191. spaceView.backgroundColor = _tableview.backgroundColor;
  192. [self addSubview:spaceView];
  193. [self addSubview:_tableview];
  194. [self addSubview:self.commentTool];
  195. //tableview顶部横线 和 顶部 view分割开
  196. tableviewLine = [[UILabel alloc]initWithFrame:CGRectMake(0, _window_height*0.3 + 49,_window_width,1)];
  197. tableviewLine.backgroundColor = Line_Cor;//[UIColor colorWithRed:198/255.0 green:198/255.0 blue:198/255.0 alpha:1];
  198. //[self addSubview:tableviewLine];
  199. [[NSNotificationCenter defaultCenter] addObserver:self
  200. selector:@selector(keyboardWillShow:)
  201. name:UIKeyboardWillShowNotification
  202. object:nil];
  203. [[NSNotificationCenter defaultCenter] addObserver:self
  204. selector:@selector(keyboardWillHide:)
  205. name:UIKeyboardWillHideNotification
  206. object:nil];
  207. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
  208. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(closeBottomTool) name:@"landForTurn" object:nil];
  209. //评论加载中
  210. [PublicView showCommenting:_tableview];
  211. [self reloaddata:from];
  212. _tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  213. count = 0;
  214. [self reloaddata:from];
  215. }];
  216. footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(reloaddata:)];
  217. footer.backgroundColor = UIColor.clearColor;
  218. [footer setTitle:YZMsg(@"评论加载中...") forState:MJRefreshStateRefreshing];
  219. [footer setTitle:@"" forState:MJRefreshStateNoMoreData];//YZMsg(@"没有更多了哦~")
  220. [footer setTitle:@"" forState:MJRefreshStateIdle];
  221. footer.stateLabel.font = [UIFont systemFontOfSize:15.0f];
  222. self.tableview.mj_footer = footer;
  223. //commectdetails 页面传过来的 点赞
  224. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload:) name:@"likesnums" object:nil];
  225. //commectdetails 页面传过来的 回复总数
  226. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadcomments:) name:@"commentnums" object:nil];
  227. //点击手势
  228. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideself)];
  229. tap.delegate = self;
  230. [self addGestureRecognizer:tap];
  231. //长按手势--【不要添加代理】
  232. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
  233. [_tableview addGestureRecognizer:longPress];
  234. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(goCenterNot:) name:@"goCenterNot" object:nil];
  235. }
  236. return self;
  237. }
  238. -(void)resetFream{
  239. isLandScreen = YES;
  240. tableheader.frame = CGRectMake(0, 0 , self.width,50);
  241. if(IS_BIG_SCREEN){
  242. if(IS_IPHONE_X){
  243. _tableview.frame = CGRectMake(0, tableheader.bottom, self.width, self.width-50);
  244. }else{
  245. _tableview.frame = CGRectMake(0, tableheader.bottom, self.width, self.width+20);
  246. }
  247. }else{
  248. _tableview.frame = CGRectMake(0, tableheader.bottom, self.width, self.width-50);
  249. }
  250. _commentTool.voiceBtn.hidden = YES;
  251. _commentTool.faceBtn.hidden = YES;
  252. _commentTool.textField.frame =CGRectMake(10,8, tableheader.width-30, 34);
  253. _commentTool.tv_bg.frame =_commentTool.textField.frame;
  254. if (_commentTool.emojiV) {
  255. [_commentTool.emojiV removeFromSuperview];
  256. }
  257. UIButton *closeBtn = [UIButton buttonWithType:0];
  258. closeBtn.frame = CGRectMake(tableheader.width-50, 10, 30, 30);
  259. [closeBtn setImage:[UIImage imageNamed:@"standardClose"] forState:0];
  260. [closeBtn addTarget:self action:@selector(closeBtnClikc) forControlEvents:UIControlEventTouchUpInside];
  261. [tableheader addSubview:closeBtn];
  262. }
  263. //-(void)closeBottomTool{
  264. // [_commentTool hiddenEmojiOrKeyBoard];
  265. //}
  266. -(void)closeBtnClikc{
  267. if(self.closeEvent){
  268. self.closeEvent();
  269. }
  270. }
  271. -(void)goCenterNot:(NSNotification*)noti {
  272. int isGo = [minstr(noti.object) intValue];
  273. if (self.goCenterEvent) {
  274. self.goCenterEvent(isGo);
  275. }
  276. }
  277. -(void)longPress:(UILongPressGestureRecognizer*)longPressGesture {
  278. if (_itemsarray.count <= 0) {
  279. return;
  280. }
  281. if ([_commentTool.textField isFirstResponder]) {
  282. [_commentTool.textField resignFirstResponder];
  283. return;
  284. }
  285. commCell *cell;
  286. if (longPressGesture.state == UIGestureRecognizerStateBegan) {
  287. CGPoint point = [longPressGesture locationInView:_tableview];
  288. NSIndexPath *currentIndexPath = [_tableview indexPathForRowAtPoint:point];
  289. if (currentIndexPath) {
  290. cell = [_tableview cellForRowAtIndexPath:currentIndexPath];
  291. }
  292. cell.longPressView.backgroundColor = RGB_COLOR(@"#ffffff", 0.1);
  293. [self showActionSheet:currentIndexPath model:cell.model];
  294. }
  295. if (longPressGesture.state == UIGestureRecognizerStateChanged || longPressGesture.state == UIGestureRecognizerStateEnded) {
  296. CGPoint point = [longPressGesture locationInView:_tableview];
  297. NSIndexPath *currentIndexPath = [_tableview indexPathForRowAtPoint:point];
  298. if (currentIndexPath) {
  299. cell = [_tableview cellForRowAtIndexPath:currentIndexPath];
  300. }
  301. cell.longPressView.backgroundColor = UIColor.clearColor;
  302. }
  303. }
  304. -(void)showActionSheet:(NSIndexPath*)indexPath model:(commentModel *)cModel{
  305. if ([[Config getOwnID] intValue] <= 0) {
  306. [self needLogin];
  307. return;
  308. }
  309. NSDictionary *subdic = _itemsarray[indexPath.row];
  310. NSDictionary *userinfo = [subdic valueForKey:@"userinfo"];
  311. BOOL isVoice = [cModel.isvoice boolValue];
  312. YBWeakSelf;
  313. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
  314. if (!isVoice) {
  315. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"复制") complete:^{
  316. dispatch_async(dispatch_get_main_queue(), ^{
  317. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  318. pasteboard.string = [NSString stringWithFormat:@"@%@:%@",cModel.user_nickname,cModel.content];
  319. [MBProgressHUD showPop:YZMsg(@"复制成功")];
  320. });
  321. }];
  322. }
  323. BOOL haveDel = NO;
  324. if ([_hostid isEqual:[Config getOwnID]] || [minstr([userinfo valueForKey:@"id"]) isEqual:[Config getOwnID]]) {
  325. haveDel = YES;
  326. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"删除") complete:^{
  327. [weakSelf delComments:subdic index:indexPath];
  328. }];
  329. }
  330. if (!isVoice || haveDel) {
  331. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  332. }];
  333. // [sheet showSheet];
  334. [sheet showLandscapeSheet:self];
  335. }
  336. }
  337. #pragma mark - 删除评论接口
  338. -(void)delComments:(NSDictionary *)subdic index:(NSIndexPath *)indexPath{
  339. NSString *commentid = minstr([subdic valueForKey:@"id"]);
  340. NSDictionary *userinfo = [subdic valueForKey:@"userinfo"];
  341. NSString *commentUid = minstr([userinfo valueForKey:@"id"]);
  342. [MBProgressHUD showMessage:@""];
  343. [YBNetworking postWithUrl:@"Video.delComments" Dic:@{@"videoid":_videoid,@"commentid":commentid,@"commentuid":commentUid} Suc:^(int code, id info, NSString *msg) {
  344. [MBProgressHUD hideHUD];
  345. [MBProgressHUD showPop:msg];
  346. if (code == 0) {
  347. count = 0;
  348. _needScroll = YES;
  349. int row = ((int)indexPath.row-1)>0?((int)indexPath.row-1):0;
  350. _needScorllToIndexPath = [NSIndexPath indexPathForRow:row inSection:0];;
  351. [self reloaddata:_fromWhere];
  352. }
  353. } Fail:^(id fail) {
  354. [MBProgressHUD hideHUD];
  355. }];
  356. }
  357. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
  358. if ([touch.view isDescendantOfView:_tableview] ||
  359. [touch.view isDescendantOfView:_commentTool] ||
  360. [touch.view isDescendantOfView:_commentTool.selV]||
  361. [touch.view isDescendantOfView:_commentTool.emojiV]||
  362. [touch.view isDescendantOfView:tableheader]) {
  363. return NO;
  364. }
  365. return YES;
  366. }
  367. -(void)hideself{
  368. if (self.mutedBlock) {
  369. self.mutedBlock(@"0");
  370. }
  371. _isPlaying = NO;
  372. if (_voicePlayer) {
  373. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_voicePlayer.currentItem];
  374. [_voicePlayer removeTimeObserver:self.playbackTimeObserver];
  375. [_voicePlayer removeObserver:self forKeyPath:@"status"];
  376. [_voicePlayer pause];
  377. _voicePlayer = nil;
  378. }
  379. _isClickCloseBtn = YES;
  380. self.hide(@"1");
  381. [self endEditing:YES];
  382. }
  383. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  384. [self.tableview deselectRowAtIndexPath:indexPath animated:NO];
  385. if ([[Config getOwnID] intValue] <= 0) {
  386. [self needLogin];
  387. return;
  388. }
  389. NSDictionary *subdic = _itemsarray[indexPath.row];
  390. NSDictionary *userinfo = [subdic valueForKey:@"userinfo"];
  391. _needScorllToIndexPath = indexPath;
  392. _currentCell = (commCell*)[tableView cellForRowAtIndexPath:indexPath];
  393. _touid = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"id"]];
  394. //20-6-28确定不能回复自己且不给提示
  395. if ([_touid isEqual:[Config getOwnID]]) {
  396. //[MBProgressHUD showPop:@"不能回复自己"];
  397. return;
  398. }
  399. if (_commentTool.voiceBtn.selected == NO) {
  400. [_commentTool.textField becomeFirstResponder];
  401. }
  402. NSString *path = [NSString stringWithFormat:@"%@:%@",YZMsg(@"回复给"),[userinfo valueForKey:@"user_nickname"]];
  403. _commentTool.textField.placeholder = path;
  404. _parentid = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"id"]];
  405. _commentid = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"commentid"]];
  406. isReply = YES;
  407. [_commentTool.voiceRecodeBtn setTitle:path forState:UIControlStateNormal];
  408. [_commentTool.voiceRecodeBtn setTitle:path forState:UIControlStateHighlighted];
  409. }
  410. //-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  411. // commentModel *model = _modelarray[indexPath.row];
  412. // return model.rowH;
  413. //}
  414. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  415. return self.itemsarray.count;
  416. }
  417. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  418. [self.tableview deselectRowAtIndexPath:indexPath animated:NO];
  419. commCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commCELL"];
  420. if (!cell) {
  421. cell = [[[NSBundle mainBundle] loadNibNamed:@"commCell" owner:nil options:nil] lastObject];
  422. }
  423. cell.authorID = _hostid;
  424. cell.videoid = _videoid;
  425. cell.model = [[commentModel alloc]initWithDic:_itemsarray[indexPath.row]];
  426. cell.delegate = self;
  427. cell.curIndex = indexPath;
  428. [cell showLandscapeSuper:self];
  429. cell.backgroundColor = UIColor.whiteColor;
  430. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  431. YBWeakSelf;
  432. cell.toolTextView = _commentTool.textField;
  433. cell.comCellEvent = ^{
  434. [weakSelf needLogin];
  435. };
  436. return cell;
  437. }
  438. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  439. //return tableheader;
  440. return nil;
  441. }
  442. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  443. //return 50;
  444. CGFloat headerH = 0.01;
  445. if (@available(iOS 13.0,*)) {
  446. headerH = 0;
  447. }
  448. return headerH;
  449. }
  450. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  451. return nil;
  452. }
  453. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  454. CGFloat footerH = 0.01;
  455. if (@available(iOS 13.0,*)) {
  456. footerH = 0;
  457. }
  458. return footerH;
  459. }
  460. //刷新评论数量
  461. -(void)getNewCount:(int)counts{
  462. _allCommentLabels.text = [NSString stringWithFormat:@"%d %@",counts,YZMsg(@"评论")];
  463. }
  464. -(void)reloadcomments:(NSNotification *)ns{
  465. NSDictionary *subdicsss = [ns userInfo];
  466. //904
  467. BOOL isLike = NO;
  468. int numbers = 0;
  469. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  470. for (int i=0; i<_itemsarray.count; i++) {
  471. NSDictionary *subdic = _itemsarray[i];
  472. NSString *parentid = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"id"]];
  473. NSString *myparentid = [NSString stringWithFormat:@"%@",[subdicsss valueForKey:@"commentid"]];
  474. if ([parentid isEqual:myparentid]) {
  475. dic = [NSMutableDictionary dictionaryWithDictionary:subdic];
  476. numbers = i;
  477. isLike = YES;
  478. break;
  479. }
  480. }
  481. if (isLike == YES) {
  482. [_itemsarray removeObject:dic];
  483. [dic setObject:[subdicsss valueForKey:@"commentnums"] forKey:@"replys"];
  484. [_itemsarray insertObject:dic atIndex:(NSUInteger)numbers];
  485. [self.tableview reloadData];
  486. }
  487. }
  488. -(void)needLogin {
  489. [_commentTool.textField resignFirstResponder];
  490. self.youkedenglu(nil);
  491. }
  492. -(void)pushmessage:(NSString *)voiceKey{
  493. if ([[Config getOwnID] intValue] <= 0) {
  494. [self needLogin];
  495. return;
  496. }
  497. /*
  498. parentid 回复的评论ID
  499. commentid 回复的评论commentid
  500. touid 回复的评论UID
  501. 如果只是评论 这三个传0
  502. */
  503. if (_commentTool.textField.text.length == 0 || _commentTool.textField.text == NULL || _commentTool.textField.text == nil || [_commentTool.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length == 0) {
  504. if ([PublicObj checkNull:voiceKey]) {
  505. [MBProgressHUD showPop:YZMsg(@"请添加内容后再尝试")];
  506. return;
  507. }
  508. }
  509. NSString *sendtouid = [NSString stringWithFormat:@"%@",_touid];
  510. NSString *sendcommentid = [NSString stringWithFormat:@"%@",_commentid];
  511. NSString *sendparentid = [NSString stringWithFormat:@"%@",_parentid];
  512. NSString *path = [NSString stringWithFormat:@"%@",_commentTool.textField.text];
  513. //隐藏
  514. // [self hideself];
  515. [self endEditing:YES];
  516. NSString *at_json = @"";
  517. //转json、去除空格、回车
  518. if (_commentTool.atArray.count>0) {
  519. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:_commentTool.atArray options:NSJSONWritingPrettyPrinted error:nil];
  520. at_json = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  521. at_json = [at_json stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  522. at_json = [at_json stringByReplacingOccurrencesOfString:@" " withString:@""];
  523. at_json = [at_json stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  524. }
  525. /*
  526. NSString *url = [NSString stringWithFormat:@"Video.setComment&videoid=%@&content=%@&uid=%@&token=%@&touid=%@&commentid=%@&parentid=%@&at_info=%@&type=%@&voice=%@&length=%@",_videoid,[PublicObj checkNull:voiceKey]?path:@"",[Config getOwnID],[Config getOwnToken],sendtouid,sendcommentid,sendparentid,at_json,[PublicObj checkNull:voiceKey]?@"0":@"1",voiceKey,[PublicObj checkNull:voiceKey]?@"0":_commentTool.voiceDution];
  527. url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  528. */
  529. NSString *url = @"Video.setComment";
  530. NSDictionary *postDic = @{@"videoid":_videoid,
  531. @"content":[PublicObj checkNull:voiceKey]?path:@"",
  532. @"touid":sendtouid,
  533. @"commentid":sendcommentid,
  534. @"parentid":sendparentid,
  535. @"at_info":at_json,
  536. @"type":[PublicObj checkNull:voiceKey]?@"0":@"1",
  537. @"voice":voiceKey?voiceKey:@"",
  538. @"length":[PublicObj checkNull:voiceKey]?@"0":_commentTool.voiceDution,
  539. };
  540. YBWeakSelf;
  541. [YBNetworking postWithUrl:url Dic:postDic Suc:^(int code, id info, NSString *msg) {
  542. [MBProgressHUD hideHUD];
  543. if (code == 0) {
  544. _commentTool.textField.text = @"";
  545. _commentTool.textField.placeholder = YZMsg(@"说点什么吧~");
  546. //论完后 把状态清零
  547. _touid = _hostid;
  548. _parentid = @"0";
  549. _commentid = @"0";
  550. [MBProgressHUD showPop:YZMsg(@"评论成功")];
  551. [_commentTool.atArray removeAllObjects];
  552. NSDictionary *infoDic = [info firstObject];
  553. //刷新评论数
  554. int allcomments = [[NSString stringWithFormat:@"%@",[infoDic valueForKey:@"comments"]] intValue];
  555. weakSelf.allCommentLabels.text = [NSString stringWithFormat:@"%d %@",allcomments,YZMsg(@"评论")];
  556. self.talkCount([NSString stringWithFormat:@"%@",[infoDic valueForKey:@"comments"]] );
  557. if (isReply) {
  558. isReply = NO;
  559. //回复评论
  560. [_currentCell requestData:YES andBtn:_currentCell.model.replyMoreBtn];
  561. }else{
  562. //对视频评论
  563. count = 0;
  564. _needScroll = YES;
  565. [self reloaddata:_fromWhere];
  566. }
  567. }else{
  568. [MBProgressHUD showPop:msg];
  569. }
  570. } Fail:^(id fail) {
  571. [MBProgressHUD hideHUD];
  572. }];
  573. }
  574. #pragma mark -- 获取键盘高度
  575. - (void)keyboardWillShow:(NSNotification *)aNotification {
  576. //tabFrame = CGRectMake(0, _window_height*0.3+50, _window_width, _window_height*0.7 - 50-ShowDiff-50);
  577. //获取键盘的高度
  578. NSDictionary *userInfo = [aNotification userInfo];
  579. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  580. CGRect keyboardRect = [aValue CGRectValue];
  581. CGFloat height = keyboardRect.origin.y;
  582. //CGFloat yyyy = keyboardRect.size.height;
  583. [UIView animateWithDuration:0.25 animations:^{
  584. //消息事件 tableview 全屏不处理frame
  585. if (![_fromWhere isEqual:@"消息事件"]) {
  586. //self.tableview.frame = CGRectMake(0, _window_height*0.3 + 50 - yyyy/2, _window_width, _window_height*0.7 - 84-statusbarHeight);
  587. /*9-17
  588. tableheader.y -= yyyy/2;
  589. _tableview.y -= yyyy/2;
  590. */
  591. /*11-16 键盘弹起不再改变 评论视图 的高度
  592. self.y = -yyyy/2;
  593. _commentTool.y = _window_height - 50 - yyyy/2;//-ShowDiff
  594. */
  595. }
  596. if(!isLandScreen){
  597. _commentTool.frame = CGRectMake(0, height - 50, _window_width, 50);
  598. _commentTool.emojiV.frame = CGRectMake(0, _window_height, _window_width, EmojiHeight+ShowDiff);
  599. }
  600. }];
  601. }
  602. - (void)keyboardWillHide:(NSNotification *)aNotification {
  603. //消息事件 tableview 全屏不处理frame
  604. if (![_fromWhere isEqual:@"消息事件"] && _isClickCloseBtn == NO) {
  605. //self.tableview.frame = CGRectMake(0, _window_height*0.3, _window_width, _window_height*0.7 - 50-ShowDiff);
  606. /*9-17
  607. tableheader.y = _window_height*0.3;
  608. _tableview.y = _window_height*0.3+50;
  609. */
  610. self.y = 0;
  611. }
  612. if(!isLandScreen){
  613. [UIView animateWithDuration:0.25 animations:^{
  614. _commentTool.frame = CGRectMake(0, _window_height - 50-ShowDiff, _window_width, 50+ShowDiff);
  615. _commentTool.emojiV.frame = CGRectMake(0, _window_height, _window_width, EmojiHeight+ShowDiff);
  616. }];
  617. }
  618. }
  619. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  620. [_commentTool.textField resignFirstResponder];
  621. }
  622. #pragma mark cell代理方法
  623. //这个地方找到点赞的字典,在数组中删除再重新插入 处理点赞
  624. -(void)makeLikeRloadList:(NSString *)commectid andLikes:(NSString *)likes islike:(NSString *)islike{
  625. int numbers = 0;
  626. for (int i=0; i<_itemsarray.count; i++) {
  627. NSMutableDictionary *subdic = _itemsarray[i];
  628. NSString *parentid = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"id"]];
  629. if ([parentid isEqual:commectid]) {
  630. [subdic setObject:likes forKey:@"likes"];
  631. [subdic setObject:islike forKey:@"islike"];
  632. numbers = i;
  633. break;
  634. }
  635. }
  636. //[self.tableview reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numbers inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  637. }
  638. -(void)reload:(NSNotification *)ns{
  639. NSDictionary *subdicsss = [ns userInfo];
  640. //904
  641. BOOL isLike = NO;
  642. int numbers = 0;
  643. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  644. for (int i=0; i<_itemsarray.count; i++) {
  645. NSDictionary *subdic = _itemsarray[i];
  646. NSString *parentid = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"id"]];
  647. NSString *myparentid = [NSString stringWithFormat:@"%@",[subdicsss valueForKey:@"commentid"]];
  648. if ([parentid isEqual:myparentid]) {
  649. dic = [NSMutableDictionary dictionaryWithDictionary:subdic];
  650. numbers = i;
  651. isLike = YES;
  652. break;
  653. }
  654. }
  655. if (isLike == YES) {
  656. [_itemsarray removeObject:dic];
  657. [dic setObject:[subdicsss valueForKey:@"likes"] forKey:@"likes"];
  658. [dic setObject:[subdicsss valueForKey:@"islike"] forKey:@"islike"];
  659. [_itemsarray insertObject:dic atIndex:(NSUInteger)numbers];
  660. [self.tableview reloadData];
  661. }
  662. }
  663. -(void)longPressing {
  664. [_commentTool.textField resignFirstResponder];
  665. }
  666. - (void)endEditOfGoHome {
  667. [self endEditing:YES];
  668. }
  669. -(void)endEnterCenter{
  670. [self hideself];
  671. }
  672. -(void)pushDetails:(NSDictionary *)commentdic andCell:(id)comcell{
  673. _currentCell = (commCell *)comcell;
  674. NSIndexPath *indexPath = [_tableview indexPathForCell:_currentCell];
  675. _needScorllToIndexPath = indexPath;
  676. NSDictionary *userinfo = [commentdic valueForKey:@"userinfo"];
  677. _touid = [NSString stringWithFormat:@"%@",[userinfo valueForKey:@"id"]];
  678. //20-6-28确定不能回复自己且不给提示
  679. if ([_touid isEqual:[Config getOwnID]]) {
  680. //[MBProgressHUD showPop:@"不能回复自己"];
  681. return;
  682. }
  683. if (_commentTool.voiceBtn.selected == NO) {
  684. [_commentTool.textField becomeFirstResponder];
  685. }
  686. NSString *path = [NSString stringWithFormat:@"%@:%@",YZMsg(@"回复给"),[userinfo valueForKey:@"user_nickname"]];
  687. _commentTool.textField.placeholder = path;
  688. _parentid = [NSString stringWithFormat:@"%@",[commentdic valueForKey:@"id"]];
  689. _commentid = [NSString stringWithFormat:@"%@",[commentdic valueForKey:@"commentid"]];
  690. isReply = YES;
  691. }
  692. - (void)playDetailesVoice:(detailmodel *)model andCell:(commDetailCell *)comcell{
  693. _isDetailPlay = YES;
  694. if (_voiceCell && _isPlaying) {
  695. _isPlaying = NO;
  696. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_voicePlayer.currentItem];
  697. [_voicePlayer removeTimeObserver:self.playbackTimeObserver];
  698. [_voicePlayer removeObserver:self forKeyPath:@"status"];
  699. [_voicePlayer pause];
  700. _voicePlayer = nil;
  701. if (self.mutedBlock) {
  702. self.mutedBlock(@"0");
  703. }
  704. _voiceCell.animationView.hidden = YES;
  705. _voiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",_voiceCell.model.voiceTime];
  706. _voiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  707. }
  708. if (_detailVoiceCell == comcell) {
  709. if (_isPlaying) {
  710. _isPlaying = NO;
  711. [_voicePlayer pause];
  712. if (self.mutedBlock) {
  713. self.mutedBlock(@"0");
  714. }
  715. _detailVoiceCell.animationView.hidden = YES;
  716. _detailVoiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",model.voiceTime];
  717. _detailVoiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  718. return;
  719. }
  720. }else{
  721. _detailVoiceCell.animationView.hidden = YES;
  722. _detailVoiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",_detailVoiceCell.model.voiceTime];
  723. _detailVoiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  724. }
  725. // if (self.mutedBlock) {
  726. // self.mutedBlock(@"1");
  727. // }
  728. // _isPlaying = NO;
  729. _detailVoiceCell = comcell;
  730. [self doplayWithModel:model];
  731. }
  732. - (void)playVoice:(commentModel *)model andCell:(id)comcell{
  733. _isDetailPlay = NO;
  734. if (_detailVoiceCell && _isPlaying) {
  735. _isPlaying = NO;
  736. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_voicePlayer.currentItem];
  737. [_voicePlayer removeTimeObserver:self.playbackTimeObserver];
  738. [_voicePlayer removeObserver:self forKeyPath:@"status"];
  739. [_voicePlayer pause];
  740. _voicePlayer = nil;
  741. if (self.mutedBlock) {
  742. self.mutedBlock(@"0");
  743. }
  744. _detailVoiceCell.animationView.hidden = YES;
  745. _detailVoiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",model.voiceTime];
  746. _detailVoiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  747. }
  748. if (_voiceCell == comcell) {
  749. if (_isPlaying) {
  750. _isPlaying = NO;
  751. [_voicePlayer pause];
  752. if (self.mutedBlock) {
  753. self.mutedBlock(@"0");
  754. }
  755. _voiceCell.animationView.hidden = YES;
  756. _voiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",model.voiceTime];
  757. _voiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  758. return;
  759. }
  760. }else{
  761. _voiceCell.animationView.hidden = YES;
  762. _voiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",_voiceCell.model.voiceTime];
  763. _voiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  764. }
  765. _voiceCell = (commCell *)comcell;
  766. [self doplayWithModel:model];
  767. }
  768. - (void)doplayWithModel:(id)mod{
  769. NSString *timeStr;
  770. NSString *url;
  771. if (_isDetailPlay) {
  772. detailmodel *model = mod;
  773. timeStr = model.voiceTime;
  774. url = model.voiceUrl;
  775. }else{
  776. commentModel *model = mod;
  777. timeStr = model.voiceTime;
  778. url = model.voiceUrl;
  779. }
  780. if (self.mutedBlock) {
  781. self.mutedBlock(@"1");
  782. }
  783. _isPlaying = NO;
  784. int floattotal = [timeStr intValue];
  785. if (_voicePlayer) {
  786. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_voicePlayer.currentItem];
  787. [_voicePlayer removeTimeObserver:self.playbackTimeObserver];
  788. [_voicePlayer removeObserver:self forKeyPath:@"status"];
  789. [_voicePlayer pause];
  790. _voicePlayer = nil;
  791. // AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:model.voiceUrl]];
  792. // [_voicePlayer replaceCurrentItemWithPlayerItem:item];
  793. }else{
  794. }
  795. // AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:url]];
  796. // _voicePlayer = [[AVPlayer alloc] initWithPlayerItem:item];
  797. NSMutableDictionary * headers = [NSMutableDictionary dictionary];
  798. [headers setObject:h5url forKey:@"referer"];
  799. AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:url] options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];
  800. // 初始化playerItem
  801. AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:urlAsset];
  802. _voicePlayer = [[AVPlayer alloc] initWithPlayerItem:item];
  803. [_voicePlayer addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
  804. YBWeakSelf;
  805. _playbackTimeObserver = [_voicePlayer addPeriodicTimeObserverForInterval:CMTimeMake(1, NSEC_PER_SEC) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
  806. //当前播放的时间
  807. CGFloat floatcurrent = CMTimeGetSeconds(time);
  808. NSLog(@"floatcurrent = %.1f",floatcurrent);
  809. //总时间
  810. if (weakSelf.isDetailPlay) {
  811. weakSelf.detailVoiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%.0f\"",(floattotal-floatcurrent) > 0 ? (floattotal-floatcurrent) : 0];
  812. }else{
  813. weakSelf.voiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%.0f\"",(floattotal-floatcurrent) > 0 ? (floattotal-floatcurrent) : 0];
  814. }
  815. }];
  816. dispatch_async(dispatch_get_main_queue(), ^{
  817. //默认情况下扬声器播放
  818. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  819. [_voicePlayer play];
  820. _voicePlayer.volume = 1;
  821. });
  822. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playFinished:) name:AVPlayerItemDidPlayToEndTimeNotification object:_voicePlayer.currentItem];
  823. }
  824. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  825. if ([keyPath isEqualToString:@"status"]) {
  826. AVPlayerStatus status = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
  827. switch (status)
  828. {
  829. /* Indicates that the status of the player is not yet known because
  830. it has not tried to load new media resources for playback */
  831. case AVPlayerStatusUnknown:
  832. {
  833. [MBProgressHUD showError:YZMsg(@"播放失败")];
  834. _isPlaying = NO;
  835. if (self.mutedBlock) {
  836. self.mutedBlock(@"0");
  837. }
  838. }
  839. break;
  840. case AVPlayerStatusReadyToPlay:
  841. {
  842. // [self creatJumpBtn];
  843. _isPlaying = YES;
  844. if (_isDetailPlay) {
  845. _detailVoiceCell.animationView.hidden = NO;
  846. _detailVoiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_play"];
  847. }else{
  848. _voiceCell.animationView.hidden = NO;
  849. _voiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_play"];
  850. }
  851. }
  852. break;
  853. case AVPlayerStatusFailed:
  854. {
  855. [MBProgressHUD showError:YZMsg(@"播放失败")];
  856. _isPlaying = NO;
  857. if (self.mutedBlock) {
  858. self.mutedBlock(@"0");
  859. }
  860. }
  861. break;
  862. }
  863. }
  864. }
  865. - (void)playFinished:(NSNotification *)not{
  866. _isPlaying = NO;
  867. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_voicePlayer.currentItem];
  868. [_voicePlayer removeTimeObserver:self.playbackTimeObserver];
  869. [_voicePlayer removeObserver:self forKeyPath:@"status"];
  870. [_voicePlayer pause];
  871. _voicePlayer = nil;
  872. if (_isDetailPlay) {
  873. _detailVoiceCell.animationView.hidden = YES;
  874. _detailVoiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",_detailVoiceCell.model.voiceTime];
  875. _detailVoiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  876. }else{
  877. _voiceCell.animationView.hidden = YES;
  878. _voiceCell.voiceTimeL.text = [NSString stringWithFormat:@"%@\"",_voiceCell.model.voiceTime];
  879. _voiceCell.voiceNorImgV.image = [UIImage imageNamed:@"comment_voice_nor"];
  880. }
  881. if (self.mutedBlock) {
  882. self.mutedBlock(@"0");
  883. }
  884. }
  885. - (void)appDidEnterBackground:(NSNotification *)not{
  886. if (_voicePlayer) {
  887. [_voicePlayer pause];
  888. [self playFinished:not];
  889. }
  890. }
  891. //- (id)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(nullable dispatch_queue_t)queue usingBlock:(void (^)(CMTime time))block;
  892. - (YBCommentToolBar *)commentTool {
  893. YBWeakSelf;
  894. if (!_commentTool) {
  895. _commentTool = [[YBCommentToolBar alloc]initWithFrame:CGRectMake(0,_window_height - 50-ShowDiff, _window_width, 50+ShowDiff) andVCType:1 superView:self];
  896. _commentTool.backgroundColor = UIColor.whiteColor;
  897. //_toolBar顶部横线 和 顶部 view分割开
  898. UILabel *lineso = [[UILabel alloc]initWithFrame:CGRectMake(0,0,_window_width,1)];
  899. lineso.backgroundColor = RGB(235, 235, 235);
  900. [_commentTool addSubview:lineso];
  901. _commentTool.comToolEvent = ^(NSString *eventType, NSDictionary *eventDic) {
  902. [weakSelf commentToolCallBack:eventType andEventDic:eventDic];
  903. };
  904. }
  905. return _commentTool;
  906. }
  907. -(void)commentToolCallBack:(NSString *)eventType andEventDic:(NSDictionary *)eventDic {
  908. if ([eventType isEqual:@"工具-游客"]) {
  909. [self needLogin];
  910. }
  911. if ([eventType isEqual:@"工具-录音"]) {
  912. //录音的时候,直接暂停播放
  913. NSString *mutedtype = minstr([eventDic valueForKey:@"mutedType"]);
  914. if ([mutedtype isEqual:@"1"]) {
  915. [self playFinished:nil];
  916. }
  917. if (self.mutedBlock) {
  918. self.mutedBlock(minstr([eventDic valueForKey:@"mutedType"]));
  919. }
  920. }
  921. if ([eventType isEqual:@"工具-发送消息"]) {
  922. NSString *voiceKey = minstr([eventDic valueForKey:@"voiceKey"]);
  923. [self pushmessage:voiceKey];
  924. }
  925. }
  926. @end