PublishLiveView.m 36 KB

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