VoiceLiveCustomView.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. //
  2. // BuguLive
  3. //
  4. // Created by xgh on 2017/8/24.
  5. // Copyright © 2017年 xfg. All rights reserved.
  6. //
  7. #import "VoiceLiveCustomView.h"
  8. #import <AVFoundation/AVFoundation.h>
  9. #import <CoreGraphics/CoreGraphics.h>
  10. #import <CoreVideo/CoreVideo.h>
  11. #import <CoreMedia/CoreMedia.h>
  12. #import "BGTLiveBeautyView.h"
  13. #import "JCTagListView.h"
  14. //#import "RoomPasswordView.h"
  15. @interface VoiceLiveCustomView()<AVCaptureVideoDataOutputSampleBufferDelegate, UITextViewDelegate,FWTLiveBeautyViewDelegate,TXVideoCustomProcessDelegate,UIGestureRecognizerDelegate,BeautySettingPanelDelegate>
  16. {
  17. AVCaptureSession *_captureSession;
  18. AVCaptureVideoPreviewLayer *_customLayer;//自定义layer展示层
  19. }
  20. @property (nonatomic, retain) AVCaptureSession *captureSession;
  21. @property (nonatomic, strong) AVCaptureVideoPreviewLayer *customLayer;
  22. @property(nonatomic, strong) UIView *lineView;
  23. @property (nonatomic, strong) TXLivePush *pusher;
  24. //@property (nonatomic, strong) TXLivePush *pusher;
  25. @property (nonatomic, strong) UIImageView *preViewContainer;
  26. @property (nonatomic, strong) TXLivePushConfig *txLivePushonfig;
  27. @property (nonatomic, strong) TXLivePlayer *txLivePlayer;
  28. @property (nonatomic, strong) TXLivePlayConfig *txLivePlayConfig;
  29. @property(nonatomic, strong) UILabel *titleL;
  30. @property(nonatomic, strong) UIView *buttonLineView;
  31. @property(nonatomic, strong) JCTagListView *tagListView;
  32. @property(nonatomic, strong) JCTagListView *tagListViewPeople;
  33. @property(nonatomic, strong) UIView *s2;
  34. @property(nonatomic, strong) UIView *s3;
  35. //@property(nonatomic, strong) RoomPasswordView *passwordView;
  36. @end
  37. @implementation VoiceLiveCustomView
  38. - (instancetype)initWithFrame:(CGRect)frame
  39. {
  40. self = [super initWithFrame:frame];
  41. if (self) {
  42. // self.topView = [[VoiceLiveTopView alloc]initWithFrame:CGRectMake(0, 10, self.width, 0.01)];
  43. // self.topView.delegate = self;
  44. // // [self initCapture];
  45. //// [self backGroundImageview];
  46. // [self addSubview:self.topView];
  47. self.people_count = @"5";
  48. UIView *middleView = [[UIView alloc]initWithFrame:CGRectMake(0, kRealValue(55) + kStatusBarHeight, kScreenW, kScreenH - self.topView.height)];
  49. // middleView.backgroundColor = [[UIColor colorWithHexString:@"#000000"] colorWithAlphaComponent:0.15];
  50. self.middleView = middleView;
  51. [self addSubview:middleView];
  52. UIButton *back = [[UIButton alloc] initWithFrame:CGRectMake(kScreenW - 10 - kRealValue(35),kStatusBarHeight + kRealValue(10), kRealValue(35), kRealValue(35))];
  53. [back setImage:[UIImage imageNamed:@"publishlive_close"] forState:UIControlStateNormal];
  54. [back addTarget:self action:@selector(handleBackEvent) forControlEvents:UIControlEventTouchUpInside];
  55. [self addSubview:back];
  56. _liveBtn = [[QMUIButton alloc] init];
  57. _liveBtn.spacingBetweenImageAndTitle = kRealValue(5);
  58. // [_liveBtn setImage:[UIImage imageNamed:@"habibi_live2"] forState:UIControlStateNormal];
  59. [_liveBtn setTitle:@"直播" forState:UIControlStateNormal];
  60. _liveBtn.imagePosition = QMUIButtonImagePositionTop;
  61. _liveBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  62. [_liveBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
  63. [self addSubview:_liveBtn];
  64. [_liveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  65. // make.top.equalTo(self.startButton.mas_bottom).offset(kRealValue(20));
  66. make.height.equalTo(@(33+10));
  67. make.width.equalTo(@(80));
  68. make.centerX.equalTo(self).offset(-kRealValue(50));
  69. make.centerY.mas_equalTo(back);
  70. }];
  71. _voiceBtn = [[QMUIButton alloc] init];
  72. _voiceBtn.spacingBetweenImageAndTitle = kRealValue(5);
  73. _voiceBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  74. // [_voiceBtn setImage:[UIImage imageNamed:@"chatparty222"] forState:UIControlStateNormal];
  75. [_voiceBtn setTitle:@"房间" forState:UIControlStateNormal];
  76. _voiceBtn.imagePosition = QMUIButtonImagePositionTop;
  77. [_voiceBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  78. [self addSubview:_voiceBtn];
  79. [_voiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80. // make.top.equalTo(self.startButton.mas_bottom).offset(kRealValue(20));
  81. make.height.equalTo(@(33+10));
  82. make.width.equalTo(@(120));
  83. make.centerX.equalTo(self).offset(kRealValue(50));
  84. make.centerY.mas_equalTo(back);
  85. }];
  86. [self setNeedsLayout];
  87. [self layoutIfNeeded];
  88. dispatch_async(dispatch_get_main_queue(), ^{
  89. [self addSubview:self.lineView];
  90. });
  91. UIView *s1 = [[UIView alloc] initWithFrame:CGRectMake(kRealValue(15), 0, self.width-kRealValue(30), kRealValue(202))];
  92. [middleView addSubview:s1];
  93. ViewRadius(s1, kRealValue(10));
  94. s1.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2];
  95. _coverBgView = [[UIView alloc] initWithFrame:CGRectMake((s1.width - kRealValue(140))/2, kRealValue(47), kRealValue(140), kRealValue(140))];
  96. self.coverBgView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2];
  97. ViewRadius(self.coverBgView, kRealValue(10));
  98. [s1 addSubview:self.coverBgView];
  99. self.selectedImageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.coverBgView.width - kRealValue(47))/2, kRealValue(35), kRealValue(47), kRealValue(40))];
  100. // ViewRadius(self.selectedImageView, kRealValue(5));
  101. // self.selectedImageView.centerX = kScreenW / 2;
  102. self.selectedImageView.image = [UIImage imageNamed:@"pl_publishlive_cover"];
  103. [self.coverBgView addSubview:self.selectedImageView];
  104. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  105. button.frame = self.coverBgView.bounds;
  106. [button addTarget:self action:@selector(selectedImageViewAction:) forControlEvents:UIControlEventTouchUpInside];
  107. self.selectedImageView.userInteractionEnabled = YES;
  108. [self.selectedImageView addSubview:button];
  109. UIImageView * coverBottomDarkImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.coverBgView.height - kRealValue(50), self.coverBgView.width, kRealValue(50))];
  110. coverBottomDarkImgV.image = [UIImage imageNamed:@"live_preview_cover_dark_bg"];
  111. [self.coverBgView addSubview:coverBottomDarkImgV];
  112. UILabel * selectCoverImgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kRealValue(22), coverBottomDarkImgV.width, 15)];
  113. selectCoverImgLabel.text = ASLocalizedString(@"选择封面");
  114. selectCoverImgLabel.font = [UIFont systemFontOfSize:14];
  115. selectCoverImgLabel.textColor = UIColor.whiteColor;
  116. selectCoverImgLabel.textAlignment = NSTextAlignmentCenter;
  117. [coverBottomDarkImgV addSubview:selectCoverImgLabel];
  118. self.textView =[[QMUITextView alloc] initWithFrame:CGRectMake(kRealValue(15), 0, self.width - kRealValue(60),kRealValue(45))];
  119. self.textView.backgroundColor =[UIColor clearColor];
  120. self.textView.keyboardType =UIKeyboardTypeDefault;
  121. self.textView.layoutManager.allowsNonContiguousLayout =NO;
  122. self.textView.textAlignment =NSTextAlignmentCenter;
  123. self.textView.textColor = RGBA(255, 255, 255, 1);
  124. self.textView.placeholderColor = RGBA(255, 255, 255, 1);
  125. self.textView.placeholder = ASLocalizedString(@"请输入直播标题");
  126. self.textView.font =[UIFont systemFontOfSize:15];
  127. // self.textView.text = ASLocalizedString(@"请输入直播标题");
  128. // self.textView.qmui_borderPosition = QMUIViewBorderPositionBottom;
  129. // self.textView.qmui_borderWidth = kRealValue(0.5);
  130. // self.textView.qmui_borderColor = RGBA(255, 255, 255, 0.4);
  131. // self.textView.hidden = YES;
  132. self.textView.delegate = self;
  133. self.autoresizingMask =UIViewAutoresizingFlexibleHeight;
  134. [s1 addSubview:self.textView];
  135. //房间分类
  136. self.s2 = [[UIView alloc] initWithFrame:CGRectMake(s1.left, s1.bottom + kRealValue(10), self.width-kRealValue(30), kRealValue(120))];
  137. [middleView addSubview:self.s2];
  138. ViewRadius(self.s2, kRealValue(10));
  139. self.s2.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2];
  140. UILabel *labRoomTag = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))];
  141. labRoomTag.text = ASLocalizedString(@"房间分类");
  142. labRoomTag.font = [UIFont systemFontOfSize:15];
  143. labRoomTag.textColor = kWhiteColor;
  144. [self.s2 addSubview:labRoomTag];
  145. self.tagListView = [[JCTagListView alloc] initWithFrame:CGRectMake(kRealValue(20), kRealValue(40), self.width - kRealValue(30), 100)];
  146. [self.s2 addSubview:self.tagListView];
  147. self.tagListView.supportSelected = YES;
  148. self.tagListView.supportMultipleSelected = NO;
  149. self.tagListView.tagSelectedBackgroundColor = UIColor.whiteColor;
  150. self.tagListView.tagBackgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4];
  151. self.tagListView.tagSelectedTextColor = [UIColor redColor];
  152. self.tagListView.tagTextColor = kWhiteColor;
  153. self.tagListView.tagCornerRadius = kRealValue(10);
  154. self.tagListView.tagSelectedBorderColor = kClearColor;
  155. self.tagListView.tagBorderColor = kClearColor;
  156. NSMutableArray *video_classified = [NSMutableArray array];
  157. for (int i = 0; i < self.BuguLive.appModel.video_classified.count; i++) {
  158. VideoClassifiedModel * model = self.BuguLive.appModel.video_classified[i];
  159. [video_classified addObject:model.title];
  160. }
  161. self.tagListView.tags = video_classified;
  162. self.cid = [NSString stringWithFormat:@"%ld",(long)((VideoClassifiedModel *)self.BuguLive.appModel.video_classified.firstObject).classified_id];
  163. self.tagListView.selectedTags = @[video_classified.firstObject];
  164. [self.tagListView didSelectItem:^(NSInteger index) {
  165. VideoClassifiedModel * model = self.BuguLive.appModel.video_classified[index];
  166. self.cid = [NSString stringWithFormat:@"%ld",(long)model.classified_id];
  167. NSLog(@"%@", @(index));
  168. }];
  169. [self.tagListView reloadData];
  170. self.tagListView.height = self.tagListView.contentHeight;
  171. self.s2.height = CGRectGetMaxY(self.tagListView.frame) + kRealValue(10);
  172. if(self.s2.height < kRealValue(60))
  173. {
  174. // self.s2.height = kRealValue(60);
  175. }
  176. // 创建s3 view
  177. self.s3 = [[UIView alloc] initWithFrame:CGRectMake(self.s2.left, self.s2.bottom + kRealValue(10), self.width-kRealValue(20), 120)];
  178. [self.middleView addSubview:self.s3];
  179. ViewRadius(self.s3, kRealValue(5));
  180. self.s3.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2];
  181. // _passwordView = [RoomPasswordView getView];
  182. // [self addSubview:_passwordView];
  183. // [_passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
  184. // make.left.equalTo(self);
  185. // make.right.equalTo(self);
  186. // make.top.equalTo(self.s3.mas_bottom).offset(20);
  187. // make.height.equalTo(@40);
  188. // }];
  189. // 添加标题
  190. UILabel *labPeople = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))];
  191. labPeople.text = ASLocalizedString(@"房间麦位");
  192. labPeople.font = [UIFont systemFontOfSize:15];
  193. labPeople.textColor = UIColor.whiteColor;
  194. [self.s3 addSubview:labPeople];
  195. // 创建tagListView
  196. self.tagListViewPeople = [[JCTagListView alloc] initWithFrame:CGRectMake(kRealValue(20), kRealValue(40), self.width - kRealValue(20), 0)];
  197. [self.s3 addSubview:self.tagListViewPeople];
  198. self.tagListViewPeople.supportSelected = YES;
  199. self.tagListViewPeople.supportMultipleSelected = NO;
  200. self.tagListViewPeople.tagSelectedBackgroundColor = UIColor.whiteColor;
  201. self.tagListViewPeople.tagBackgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4];
  202. self.tagListViewPeople.tagSelectedTextColor = [UIColor redColor];
  203. self.tagListViewPeople.tagTextColor = kWhiteColor;
  204. self.tagListViewPeople.tagCornerRadius = kRealValue(10);
  205. self.tagListViewPeople.tagSelectedBorderColor = kClearColor;
  206. self.tagListViewPeople.tagBorderColor = kClearColor;
  207. self.tagListViewPeople.tags = @[ASLocalizedString(@"5人房"), ASLocalizedString(@"10人房"),ASLocalizedString(@"15人房"),ASLocalizedString(@"20人房")];
  208. [self.tagListViewPeople didSelectItem:^(NSInteger index) {
  209. NSLog(@"%@", @(index));
  210. if(index == 0)
  211. {
  212. self.people_count = @"5";
  213. }
  214. else if(index == 1)
  215. {
  216. self.people_count = @"10";
  217. }
  218. else if(index == 2)
  219. {
  220. self.people_count = @"15";
  221. }
  222. else
  223. {
  224. self.people_count = @"20";
  225. }
  226. }];
  227. [self.tagListViewPeople reloadData];
  228. self.tagListViewPeople.height = self.tagListViewPeople.contentHeight;
  229. self.s3.height = CGRectGetMaxY(self.tagListViewPeople.frame) + kRealValue(10);
  230. // if(self.s3.height < kRealValue(120))
  231. // {
  232. // self.s3.height = kRealValue(120);
  233. // }
  234. //房间密码
  235. UIView * passwordView = [[UIView alloc] initWithFrame:CGRectMake(s1.left, self.s3.bottom + kRealValue(10), self.width-kRealValue(30), kRealValue(60))];
  236. [middleView addSubview:passwordView];
  237. ViewRadius(passwordView, kRealValue(10));
  238. passwordView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2];
  239. UILabel *passwordTitle = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))];
  240. passwordTitle.text = ASLocalizedString(@"房间密码");
  241. passwordTitle.font = [UIFont systemFontOfSize:15];
  242. passwordTitle.textColor = kWhiteColor;
  243. [passwordView addSubview:passwordTitle];
  244. UIView * passwordBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(10, passwordView.height -9, passwordView.width - 20, 1)];
  245. passwordBottomLineView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4];
  246. [passwordView addSubview:passwordBottomLineView];
  247. _passWordButton = [UIButton buttonWithType:UIButtonTypeCustom];
  248. [self.passWordButton setImage:[UIImage imageNamed:@"live_switch_off"] forState:UIControlStateNormal];
  249. [self.passWordButton setImage:[UIImage imageNamed:@"live_switch_on"] forState:UIControlStateSelected];
  250. self.passWordButton.frame = CGRectMake(passwordView.width - 10 - 30, 10, 30, 14);
  251. [passwordView addSubview:self.passWordButton];
  252. [self.passWordButton addTarget:self action:@selector(passWordButtonClick) forControlEvents:UIControlEventTouchUpInside];
  253. _passTF = [[UITextField alloc] initWithFrame:CGRectMake(10, passwordTitle.bottom + 5, passwordView.width - 20, 20)];
  254. self.passTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入4-8位数字密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#999999"]}];
  255. self.passTF.textColor = UIColor.whiteColor;
  256. self.passTF.font = [UIFont systemFontOfSize:12];
  257. self.passTF.keyboardType = UIKeyboardTypeNumberPad;
  258. [passwordView addSubview:_passTF];
  259. //进入门票
  260. UIView * ticketView = [[UIView alloc] initWithFrame:CGRectMake(s1.left, passwordView.bottom + kRealValue(10), self.width-kRealValue(30), kRealValue(60))];
  261. [middleView addSubview:ticketView];
  262. ViewRadius(ticketView, kRealValue(10));
  263. ticketView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2];
  264. UILabel *ticketTitle = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))];
  265. ticketTitle.text = ASLocalizedString(@"进入门票");
  266. ticketTitle.font = [UIFont systemFontOfSize:15];
  267. ticketTitle.textColor = kWhiteColor;
  268. [ticketView addSubview:ticketTitle];
  269. UIView * ticketBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(10, ticketView.height -9, ticketView.width - 20, 1)];
  270. ticketBottomLineView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4];
  271. [ticketView addSubview:ticketBottomLineView];
  272. _enterTicketButton = [UIButton buttonWithType:UIButtonTypeCustom];
  273. [self.enterTicketButton setImage:[UIImage imageNamed:@"live_switch_off"] forState:UIControlStateNormal];
  274. [self.enterTicketButton setImage:[UIImage imageNamed:@"live_switch_on"] forState:UIControlStateSelected];
  275. self.enterTicketButton.frame = CGRectMake(ticketView.width - 10 - 30, 10, 30, 14);
  276. [ticketView addSubview:self.enterTicketButton];
  277. [self.enterTicketButton addTarget:self action:@selector(enterTicketButtonClick) forControlEvents:UIControlEventTouchUpInside];
  278. _ticketTF = [[UITextField alloc] initWithFrame:CGRectMake(10, ticketTitle.bottom + 5, ticketView.width - 20, 20)];
  279. self.ticketTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"最低设置为1钻石" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#999999"]}];
  280. self.ticketTF.textColor = UIColor.whiteColor;
  281. self.ticketTF.font = [UIFont systemFontOfSize:12];
  282. self.ticketTF.keyboardType = UIKeyboardTypeNumberPad;
  283. [ticketView addSubview:self.ticketTF];
  284. UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(self.width / 2 - 50, self.selectedImageView.bottom + 15, 100, 20)];
  285. lab.text = ASLocalizedString(@"选择封面");
  286. lab.textColor = kWhiteColor;
  287. lab.font = [UIFont systemFontOfSize:15];
  288. lab.textAlignment = NSTextAlignmentCenter;
  289. lab.hidden = YES;
  290. self.titleL = lab;
  291. [self.middleView addSubview:lab];
  292. self.beautyBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  293. [self.beautyBtn setImage:[UIImage imageNamed:@"ic_live_beauty"] forState:UIControlStateNormal];
  294. [self.beautyBtn setTitle:ASLocalizedString(@"美颜")forState:UIControlStateNormal];
  295. [self.beautyBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  296. self.beautyBtn.imagePosition = QMUIButtonImagePositionTop;
  297. self.beautyBtn.spacingBetweenImageAndTitle = 2;
  298. self.beautyBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  299. self.beautyBtn.frame = CGRectMake(kRealValue(40) , self.height - kRealValue(120), kRealValue(40), kRealValue(50));
  300. self.beautyBtn.hidden = YES;
  301. [self.beautyBtn addTarget:self action:@selector(clickBeauty:) forControlEvents:UIControlEventTouchUpInside];
  302. NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key;
  303. self.beautyBtn.hidden = [BGUtils isBlankString:key];
  304. [self addSubview:self.beautyBtn];
  305. self.beautyBtn.hidden = YES;
  306. // self.textView.top = lab.bottom + 30;
  307. self.startButton = [UIButton buttonWithType:UIButtonTypeCustom];
  308. // self.startButton.frame = CGRectMake(self.beautyBtn.right + kRealValue(25), self.height - 120, kRealValue(220), kRealValue(45));
  309. self.startButton.frame = CGRectMake((self.width - 200)/2, self.height - kRealValue(55) - SafeAreaBottomHeight - 10, 200, kRealValue(55));
  310. // self.startButton.centerY = self.beautyBtn.centerY;
  311. self.startButton.titleLabel.font = [UIFont systemFontOfSize:14];
  312. [self.startButton addTarget:self action:@selector(startbuttonAction) forControlEvents:UIControlEventTouchUpInside];
  313. [self.startButton setTitle:ASLocalizedString(@"开始直播")forState:UIControlStateNormal];
  314. // [self.startButton setBackgroundImage:[UIImage imageWithColor:[UIColor qmui_colorWithHexString:@"#AE2CF1"]] forState:UIControlStateNormal];
  315. [self.startButton setBackgroundImage:[UIImage imageNamed:@"live_beginLiveBg"] forState:UIControlStateNormal];
  316. [self.startButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  317. self.startButton.titleLabel.font = [UIFont systemFontOfSize:16];
  318. self.startButton.layer.masksToBounds = YES;
  319. self.startButton.layer.cornerRadius = kRealValue(22.5);
  320. [self addSubview:self.startButton];
  321. [self setUpBeautyView];
  322. [self setTxPreview];
  323. [self resetViewWithTitleTop:kRealValue(23) + kStatusBarHeight];
  324. if (0) {
  325. [self addSubview:self.videoPushBtn];
  326. [self addSubview:self.otherPushBtn];
  327. [self addSubview:self.lineView];
  328. }
  329. }
  330. return self;
  331. }
  332. - (void)passWordButtonClick {
  333. self.passWordButton.selected = !self.passWordButton.isSelected;
  334. }
  335. - (void)enterTicketButtonClick {
  336. self.enterTicketButton.selected = !self.enterTicketButton.isSelected;
  337. }
  338. - (void)handleBackEvent {
  339. if (self.delegate && [self.delegate respondsToSelector:@selector(closeThestartLiveViewDelegate)]) {
  340. [self.delegate closeThestartLiveViewDelegate];
  341. }
  342. }
  343. -(void)resetViewWithTitleTop:(CGFloat)top{
  344. top = kRealValue(55) + kStatusBarHeight;
  345. self.middleView.top = top;
  346. // self.selectedImageView.top = top;
  347. self.titleL.top = self.selectedImageView.bottom + kRealValue(15);
  348. // self.textView.top = top;
  349. }
  350. -(void)setUpBeautyView{
  351. // ///////////// TiSDK 添加 开始 ////////////
  352. // self.tiSDKManager = [[TiSDKManager alloc]init];
  353. NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key;
  354. // NSString* key = @"";
  355. [TiSDK init:key CallBack:^(InitStatus initStatus) {
  356. [[NSNotificationCenter defaultCenter] postNotificationName:@"TiSDKInitStatusNotification" object:nil];
  357. }];
  358. // [TiSDKManager shareManager]
  359. // [[TiUIManager shareManager] loadToSuperview:self.view];
  360. [TiUIManager shareManager].showsDefaultUI = YES;
  361. [[TiUIManager shareManager]loadToWindowDelegate:nil];
  362. }
  363. -(void)setTxPreview{
  364. [self setBackgroundColor:kBlackColor];
  365. _txLivePushonfig = [[TXLivePushConfig alloc] init];
  366. _txLivePushonfig.frontCamera = YES;
  367. _txLivePushonfig.enableAEC = YES;
  368. _txLivePushonfig.enableHWAcceleration = YES;
  369. _txLivePushonfig.enableAutoBitrate = NO;
  370. _txLivePushonfig.audioChannels = 1; // 单声道
  371. GlobalVariables *BuguLive = [GlobalVariables sharedInstance];
  372. // 0:标清(360*640) 1:高清(540*960) 2:超清(720*1280)
  373. if (BuguLive.appModel.video_resolution_type == 0)
  374. {
  375. _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_360_640;
  376. _txLivePushonfig.videoBitratePIN = 700;
  377. }
  378. else if (BuguLive.appModel.video_resolution_type == 1)
  379. {
  380. _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_540_960;
  381. _txLivePushonfig.videoBitratePIN = 1000;
  382. }
  383. else if (BuguLive.appModel.video_resolution_type == 2)
  384. {
  385. _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_720_1280;
  386. _txLivePushonfig.videoBitratePIN = 1500;
  387. }
  388. _txLivePushonfig.autoAdjustStrategy = NO;
  389. _txLivePushonfig.videoFPS = 20;
  390. _txLivePushonfig.audioSampleRate = AUDIO_SAMPLE_RATE_48000; // 不要用其它的
  391. _txLivePushonfig.pauseFps = 10;
  392. _txLivePushonfig.pauseTime = 300;
  393. _txLivePushonfig.pauseImg = [UIImage imageNamed:@"lr_bg_leave.png"];
  394. // _pusher = [[TXLivePush alloc] initWithConfig:_txLivePushonfig];
  395. // 设置日志级别
  396. [TXLiveBase setLogLevel:LOGLEVEL_NULL];
  397. // 初始化视频父视图
  398. _preViewContainer = [[UIImageView alloc] initWithFrame:self.bounds];
  399. _preViewContainer.image = [UIImage imageNamed:@"live_preview_bg"];
  400. [self insertSubview:_preViewContainer atIndex:0];
  401. _preViewContainer.center = self.center;
  402. // [_pusher startPreview:_preViewContainer];
  403. // _pusher.videoProcessDelegate = self;
  404. // UITapGestureRecognizer *tapBgView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBgView:)];
  405. // tapBgView.delegate = self;
  406. // [_preViewContainer addGestureRecognizer:tapBgView];
  407. // [self addGestureRecognizer:tapBgView];
  408. }
  409. //#pragma mark ---------美颜增加-------------
  410. //- (GLuint)onPreProcessTexture:(GLuint)texture width:(CGFloat)width height:(CGFloat)height{
  411. // return [[TiSDKManager shareManager] renderTexture2D:texture Width:width Height:height Rotation:CLOCKWISE_0 Mirror:_pusher.config.frontCamera];
  412. //}
  413. -(void)clickBgView:(UITapGestureRecognizer *)sender{
  414. [self.textView resignFirstResponder];
  415. _beautyPanel.hidden = YES;
  416. }
  417. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
  418. [self.textView resignFirstResponder];
  419. return YES;
  420. }
  421. - (void)selectedTheClassirmAction
  422. {
  423. //选择分类
  424. }
  425. - (void)startbuttonAction
  426. {
  427. if (self.otherPushBtn.isSelected) {
  428. [_pusher stopPreview];
  429. }
  430. if (self.delegate && [self.delegate respondsToSelector:@selector(startThePublishLiveDelegate)]) {
  431. [self.delegate startThePublishLiveDelegate];
  432. }
  433. }
  434. -(void)clickPasswordActionDelegate:(BOOL)password{
  435. if (self.delegate && [self.delegate respondsToSelector:@selector(clickPasswordActionDelegate:)]) {
  436. [self.delegate clickPasswordActionDelegate:password];
  437. }
  438. }
  439. -(void)clickShopActionDelegate:(BOOL)shop{
  440. if (self.delegate && [self.delegate respondsToSelector:@selector(clickShopActionDelegate:)]) {
  441. [self.delegate clickShopActionDelegate:shop];
  442. }
  443. }
  444. - (void)closeThePublishLive:(PublishLiveTopView *)topView
  445. {
  446. //关闭开始直播界面
  447. if(self.delegate && [self.delegate respondsToSelector:@selector(closeThestartLiveViewDelegate)]) {
  448. [self.delegate closeThestartLiveViewDelegate];
  449. }
  450. }
  451. - (void)ispracychangeActionDelegate:(BOOL)ispraicy
  452. {
  453. self.shareView.hidden = ispraicy;
  454. }
  455. - (UIImageView *)backGroundImageview {
  456. if (_backGroundImageview == nil) {
  457. _backGroundImageview = [[UIImageView alloc]initWithFrame:self.bounds];
  458. [self addSubview:_backGroundImageview];
  459. UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
  460. UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:beffect];
  461. view.frame = _backGroundImageview.bounds;
  462. [_backGroundImageview addSubview:view];
  463. [_backGroundImageview sd_setImageWithURL:[NSURL URLWithString:[[IMAPlatform sharedInstance].host imUserIconUrl]]];
  464. }
  465. return _backGroundImageview;
  466. }
  467. /**
  468. 初始化摄像头
  469. */
  470. - (void) initCapture
  471. {
  472. self.captureSession = [[AVCaptureSession alloc] init];
  473. for (AVCaptureDevice *d in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
  474. if ([d position] == AVCaptureDevicePositionFront) {
  475. [self.captureSession beginConfiguration];
  476. AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:d error:nil];
  477. for (AVCaptureInput *oldInput in self.captureSession.inputs) {
  478. [self.captureSession removeInput:oldInput];
  479. }
  480. [self.captureSession addInput:input];
  481. [self.captureSession commitConfiguration];
  482. break;
  483. }
  484. }
  485. [self.captureSession startRunning];
  486. self.customLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];;
  487. CGRect frame = self.bounds;
  488. self.customLayer.frame = frame;
  489. self.customLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
  490. [self.layer addSublayer:self.customLayer];
  491. }
  492. - (void)selectedImageViewAction:(UIButton *)sender
  493. {
  494. if(self.delegate && [self.delegate respondsToSelector:@selector(selectedTheImageDelegate)]) {
  495. [self.delegate selectedTheImageDelegate];
  496. }
  497. }
  498. -(void)clickBeauty:(UIButton *)sender{
  499. [[TiUIManager shareManager]showMainMenuView];
  500. }
  501. #pragma mark - BeautySettingPanelDelegate
  502. - (void)onSetBeautyStyle:(NSUInteger)beautyStyle beautyLevel:(float)beautyLevel whitenessLevel:(float)whitenessLevel ruddinessLevel:(float)ruddinessLevel {
  503. [_pusher setBeautyStyle:beautyStyle beautyLevel:beautyLevel whitenessLevel:whitenessLevel ruddinessLevel:ruddinessLevel];
  504. }
  505. - (void)onSetMixLevel:(float)mixLevel {
  506. [_pusher setSpecialRatio:mixLevel / 10.0];
  507. }
  508. - (void)onSetEyeScaleLevel:(float)eyeScaleLevel {
  509. [_pusher setEyeScaleLevel:eyeScaleLevel];
  510. }
  511. - (void)onSetFaceScaleLevel:(float)faceScaleLevel {
  512. [_pusher setFaceScaleLevel:faceScaleLevel];
  513. }
  514. - (void)onSetFaceBeautyLevel:(float)beautyLevel {
  515. }
  516. - (void)onSetFaceVLevel:(float)vLevel {
  517. [_pusher setFaceVLevel:vLevel];
  518. }
  519. - (void)onSetChinLevel:(float)chinLevel {
  520. [_pusher setChinLevel:chinLevel];
  521. }
  522. - (void)onSetFaceShortLevel:(float)shortLevel {
  523. [_pusher setFaceShortLevel:shortLevel];
  524. }
  525. - (void)onSetNoseSlimLevel:(float)slimLevel {
  526. [_pusher setNoseSlimLevel:slimLevel];
  527. }
  528. - (void)onSetFilter:(UIImage*)filterImage {
  529. [_pusher setFilter:filterImage];
  530. }
  531. - (void)onSetGreenScreenFile:(NSURL *)file {
  532. [_pusher setGreenScreenFile:file];
  533. }
  534. - (void)onSelectMotionTmpl:(NSString *)tmplName inDir:(NSString *)tmplDir {
  535. [_pusher selectMotionTmpl:tmplName inDir:tmplDir];
  536. }
  537. - (void)classifyButtonActionDelegate {
  538. if (self.delegate && [self.delegate respondsToSelector:@selector(selectedTheClassifyDelegate)]) {
  539. [self.delegate selectedTheClassifyDelegate];
  540. }
  541. }
  542. #pragma mark - UITextViewDelegate
  543. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView
  544. {
  545. if ([self.textView.text isEqualToString:ASLocalizedString(@"#添加标题上热门更轻松")]) {
  546. self.textView.text = @"";
  547. [self resetViewWithTitleTop:kRealValue(23) + kStatusBarHeight];
  548. }
  549. return YES;
  550. }
  551. - (BOOL)textViewShouldEndEditing:(UITextView *)textView
  552. {
  553. if ([self.textView.text isEqualToString:@""]) {
  554. self.textView.text = ASLocalizedString(@"#添加标题上热门更轻松");
  555. }
  556. [self resetViewWithTitleTop:kRealValue(23) + kStatusBarHeight];
  557. return YES;
  558. }
  559. - (UIButton *)videoPushBtn{
  560. if (!_videoPushBtn){
  561. _videoPushBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, self.startButton.bottom + 10, (self.width - 40 ) / 2, 35)];
  562. [_videoPushBtn setTitleColor:kWhiteColor forState:UIControlStateSelected];
  563. _videoPushBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  564. [_videoPushBtn setTitleColor:[kWhiteColor colorWithAlphaComponent:0.8] forState:UIControlStateNormal];
  565. [_videoPushBtn setTitle:ASLocalizedString(@"视频直播") forState:UIControlStateNormal];
  566. [_videoPushBtn addTarget:self action:@selector(videoPushBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  567. _videoPushBtn.selected = YES;
  568. }
  569. return _videoPushBtn;
  570. }
  571. - (UIButton *)otherPushBtn{
  572. if (!_otherPushBtn){
  573. _otherPushBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.width / 2, self.startButton.bottom + 10, (self.width - 40 ) / 2, 35)];
  574. [_otherPushBtn setTitleColor:kWhiteColor forState:UIControlStateSelected];
  575. _otherPushBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  576. [_otherPushBtn setTitleColor:[kWhiteColor colorWithAlphaComponent:0.8] forState:UIControlStateNormal];
  577. [_otherPushBtn setTitle:ASLocalizedString(@"外设直播") forState:UIControlStateNormal];
  578. [_otherPushBtn addTarget:self action:@selector(otherPushBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  579. }
  580. return _otherPushBtn;
  581. }
  582. - (void)videoPushBtnAction:(UIButton *)sender{
  583. [self.pusher startPreview:_preViewContainer];
  584. sender.selected = YES;
  585. self.otherPushBtn.selected = NO;
  586. self.lineView.centerX = sender.centerX;
  587. self.beautyBtn.hidden = YES;
  588. self.startButton.frame = CGRectMake(self.beautyBtn.right + kRealValue(25), self.height - 120, kRealValue(220), kRealValue(45));
  589. [self.startButton setTitle:@"开始直播" forState:UIControlStateNormal];
  590. }
  591. - (void)otherPushBtnAction:(UIButton *)sender{
  592. [self.pusher stopPreview];
  593. sender.selected = YES;
  594. self.videoPushBtn.selected = NO;
  595. self.lineView.centerX = sender.centerX;
  596. self.beautyBtn.hidden = YES;
  597. self.startButton.frame = CGRectMake(kRealValue(50), self.height - 120, kScreenW - kRealValue(100), kRealValue(45));
  598. [self.startButton setTitle:@"创建外设直播" forState:UIControlStateNormal];
  599. }
  600. - (UIView *)lineView{
  601. if (!_lineView) {
  602. _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 4)];
  603. _lineView.backgroundColor = kWhiteColor;
  604. _lineView.layer.cornerRadius = 2;
  605. _lineView.clipsToBounds = YES;
  606. _lineView.top = self.liveBtn.bottom;
  607. _lineView.centerX = self.voiceBtn.centerX;
  608. }
  609. return _lineView;
  610. }
  611. //// 创建推流器,并使用本地配置初始化它
  612. //- (TXLivePush *)createPusher {
  613. // // config初始化
  614. // TXLivePushConfig *config = [[TXLivePushConfig alloc] init];
  615. // config.pauseFps = 10;
  616. // config.pauseTime = 300;
  617. // config.pauseImg = [UIImage imageNamed:@"pause_publish"];
  618. //// config.touchFocus = [PushMoreSettingViewController isEnableTouchFocus];
  619. //// config.enableZoom = [PushMoreSettingViewController isEnableVideoZoom];
  620. //// config.enableAudioPreview = [PushSettingViewController getEnableAudioPreview];
  621. //// config.frontCamera = _btnCamera.tag == 0 ? YES : NO;
  622. // if ([PushMoreSettingViewController isEnableWaterMark]) {
  623. // config.watermark = [UIImage imageNamed:@"watermark"];
  624. // config.watermarkPos = CGPointMake(10, 10);
  625. // }
  626. //
  627. // // 推流器初始化
  628. // TXLivePush *pusher = [[TXLivePush alloc] initWithConfig:config];
  629. //// [pusher setReverbType:[PushSettingViewController getReverbType]];
  630. //// [pusher setVoiceChangerType:[PushSettingViewController getVoiceChangerType]];
  631. //// [pusher toggleTorch:[PushMoreSettingViewController isOpenTorch]];
  632. //// [pusher setMirror:[PushMoreSettingViewController isMirrorVideo]];
  633. //// [pusher setMute:[PushMoreSettingViewController isMuteAudio]];
  634. //// [pusher setVideoQuality:[PushSettingViewController getVideoQuality] adjustBitrate:[PushSettingViewController getBandWidthAdjust] adjustResolution:NO];
  635. //
  636. // // 修改软硬编需要在setVideoQuality之后设置config.enableHWAcceleration
  637. // config.enableHWAcceleration = [PushSettingViewController getEnableHWAcceleration];
  638. //
  639. // // 横屏推流需要先设置config.homeOrientation = HOME_ORIENTATION_RIGHT,然后再[pusher setRenderRotation:90]
  640. // config.homeOrientation = ([PushMoreSettingViewController isHorizontalPush] ? HOME_ORIENTATION_RIGHT : HOME_ORIENTATION_DOWN);
  641. // if ([PushMoreSettingViewController isHorizontalPush]) {
  642. // [pusher setRenderRotation:90];
  643. // } else {
  644. // [pusher setRenderRotation:0];
  645. // }
  646. //
  647. // [pusher setLogViewMargin:UIEdgeInsetsMake(120, 10, 60, 10)];
  648. // [pusher showVideoDebugLog:[PushMoreSettingViewController isShowDebugLog]];
  649. // [pusher setEnableClockOverlay:[PushMoreSettingViewController isEnableDelayCheck]];
  650. //
  651. // [pusher setVideoProcessDelegate:self];
  652. //
  653. // [pusher setConfig:config];
  654. //
  655. // return pusher;
  656. //}
  657. //lineView 懒加载
  658. - (UIView *)buttonLineView{
  659. if (!_buttonLineView) {
  660. _buttonLineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 15, 4)];
  661. _buttonLineView.backgroundColor = kWhiteColor;
  662. _buttonLineView.layer.cornerRadius = 1.5;
  663. _buttonLineView.clipsToBounds = YES;
  664. // _buttonLineView.top = self.videoPushBtn.bottom - 4;
  665. _buttonLineView.centerX = self.videoPushBtn.centerX;
  666. _buttonLineView.top = self.videoPushBtn.bottom + 4;
  667. }
  668. return _buttonLineView;
  669. }
  670. @end