NIMSessionVideoContentView.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // NIMSessionVideoContentView.m
  3. // NIMKit
  4. //
  5. // Created by chris on 15/4/10.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMSessionVideoContentView.h"
  9. #import "NIMMessageModel.h"
  10. #import "UIView+NIM.h"
  11. #import "UIImage+NIMKit.h"
  12. #import "NIMLoadProgressView.h"
  13. @interface NIMSessionVideoContentView()
  14. @property (nonatomic,strong,readwrite) UIImageView * imageView;
  15. @property (nonatomic,strong) UIButton *playBtn;
  16. @property (nonatomic,strong) NIMLoadProgressView * progressView;
  17. @end
  18. @implementation NIMSessionVideoContentView
  19. - (instancetype)initSessionMessageContentView{
  20. self = [super initSessionMessageContentView];
  21. if (self) {
  22. self.opaque = YES;
  23. _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  24. _imageView.backgroundColor = [UIColor blackColor];
  25. [self addSubview:_imageView];
  26. _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  27. [_playBtn setImage:[UIImage nim_imageInKit:@"icon_play_normal"] forState:UIControlStateNormal];
  28. [_playBtn sizeToFit];
  29. [_playBtn setUserInteractionEnabled:NO];
  30. [self addSubview:_playBtn];
  31. _progressView = [[NIMLoadProgressView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
  32. _progressView.maxProgress = 1.0;
  33. [self addSubview:_progressView];
  34. }
  35. return self;
  36. }
  37. - (void)refresh:(NIMMessageModel *)data{
  38. [super refresh:data];
  39. NIMVideoObject * videoObject = (NIMVideoObject*)self.model.message.messageObject;
  40. UIImage * image = [UIImage imageWithContentsOfFile:videoObject.coverPath];
  41. self.imageView.image = image;
  42. CGSize contentSize = [data contentSize:self.superview.nim_width];
  43. self.bounds = CGRectMake(0, 0,contentSize.width, contentSize.height);
  44. self.imageView.frame = self.bounds;
  45. //设置气泡为空
  46. [self.bubbleImageView setImage:nil];
  47. [self.bubbleImageView setHighlightedImage:nil];
  48. //设置遮罩
  49. UIImageView* maskImageView = [[UIImageView alloc]init];
  50. [maskImageView setImage:[self chatBubbleImageForState:UIControlStateNormal outgoing:data.message.isOutgoingMsg]];
  51. maskImageView.frame = self.bounds;
  52. self.imageView.maskView = maskImageView;
  53. _progressView.hidden = (self.model.message.deliveryState != NIMMessageDeliveryStateDelivering);
  54. if (!_progressView.hidden) {
  55. [_progressView setProgress:[[[NIMSDK sharedSDK] chatManager] messageTransportProgress:self.model.message]];
  56. }
  57. }
  58. - (void)layoutSubviews{
  59. [super layoutSubviews];
  60. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  61. CGFloat tableViewWidth = self.superview.nim_width;
  62. CGSize contentsize = [self.model contentSize:tableViewWidth];
  63. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
  64. self.imageView.frame = imageViewFrame;
  65. self.imageView.maskView.frame = imageViewFrame;
  66. _progressView.frame = self.bounds;
  67. // CALayer *maskLayer = [CALayer layer];
  68. // maskLayer.cornerRadius = 13.0;
  69. // maskLayer.backgroundColor = [UIColor blackColor].CGColor;
  70. // maskLayer.frame = self.imageView.bounds;
  71. // self.imageView.layer.mask = maskLayer;
  72. self.playBtn.nim_centerX = self.nim_width * .5f;
  73. self.playBtn.nim_centerY = self.nim_height * .5f;
  74. }
  75. - (void)onTouchUpInside:(id)sender
  76. {
  77. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  78. event.eventName = NIMKitEventNameTapContent;
  79. event.messageModel = self.model;
  80. [self.delegate onCatchEvent:event];
  81. }
  82. - (void)updateProgress:(float)progress
  83. {
  84. if (progress > 1.0) {
  85. progress = 1.0;
  86. }
  87. self.progressView.progress = progress;
  88. }
  89. @end