Files
yinmeng-ios/xplan-ios/Main/Message/View/Session/SessionAudioRecordView.m
2022-05-13 16:12:18 +08:00

149 lines
4.0 KiB
Objective-C

//
// SessionAudioRecordView.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/21.
//
#import "SessionAudioRecordView.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
@interface SessionAudioRecordView ()
///背景
@property (nonatomic,strong) UIView * backView;
///显示图片
@property (nonatomic,strong) UIImageView *logoImageView;
///显示标题
@property (nonatomic,strong) UILabel *titleLabel;
///当前时间
@property (nonatomic,strong) UILabel *timeLabel;
@end
@implementation SessionAudioRecordView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Public Method
- (void)configAudioRecord:(NSString *)imageName title:(NSString *)title isAnimation:(BOOL)isAnimation {
self.logoImageView.image = [UIImage imageNamed:imageName];
if (isAnimation) {
[self.logoImageView startAnimating];
} else {
[self.logoImageView stopAnimating];
}
self.titleLabel.text = title;
}
///开始录音
- (void)beginAudioRecord {
self.timeLabel.text = @"00:00";
[[NIMSDK sharedSDK].mediaManager recordForDuration:60];
}
///取消录音
- (void)cancelAudioRecord {
self.timeLabel.text = @"00:00";
[[NIMSDK sharedSDK].mediaManager cancelRecord];
}
///完成录音
- (void)finishAudioRecord {
self.timeLabel.text = @"00:00";
[[NIMSDK sharedSDK].mediaManager stopRecord];
}
- (void)updateAudioRecordProgress:(NSTimeInterval)recordTime {
NSInteger minutes = (NSInteger)recordTime / 60;
NSInteger seconds = (NSInteger)recordTime % 60;
self.timeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd", minutes, seconds];
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.backView];
[self.backView addSubview:self.logoImageView];
[self.backView addSubview:self.titleLabel];
[self.backView addSubview:self.timeLabel];
}
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(250, 200));
}];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView);
make.top.mas_equalTo(self.backView).offset(15);
}];
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.backView);
make.top.mas_equalTo(self.backView).offset(50);
make.size.mas_equalTo(CGSizeMake(90, 72));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backView);
make.top.mas_equalTo(self.logoImageView.mas_bottom).offset(25);
}];
}
#pragma mark - Getters And Setters
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [UIColor blackColor];
_backView.layer.masksToBounds = YES;
_backView.layer.cornerRadius = 10;
}
return _backView;
}
- (UIImageView *)logoImageView {
if (!_logoImageView) {
_logoImageView = [[UIImageView alloc] init];
_logoImageView.userInteractionEnabled = YES;
UIImage *firstImage = [UIImage imageNamed:@"message_tool_audio_record_first"];
UIImage *secondImage = [UIImage imageNamed:@"message_tool_audio_record_second"];
UIImage *thirdImage = [UIImage imageNamed:@"message_tool_audio_record_third"];
_logoImageView.animationImages = @[firstImage, secondImage, thirdImage];
_logoImageView.animationDuration = 1;
_logoImageView.animationRepeatCount = HUGE;
}
return _logoImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:15];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
- (UILabel *)timeLabel {
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init];
_timeLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightMedium];
_timeLabel.textColor = [UIColor whiteColor];
_timeLabel.textAlignment = NSTextAlignmentCenter;
}
return _timeLabel;
}
@end