BGTPlayController.m 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. //
  2. // BGTPlayController.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 16/12/5.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "BGTPlayController.h"
  9. #import <TXLiteAVSDK_Professional/TXLivePlayListener.h>
  10. #import <TXLiteAVSDK_Professional/TXLiveBase.h>
  11. #import <mach/mach.h>
  12. #import "BogoPkProgressModel.h"
  13. #define TEST_MUTE 0
  14. #define RTMP_URL ASLocalizedString(@"请输入或扫二维码获取播放地址")
  15. #define kRePlayTime 1 // 断开后重新尝试的次数
  16. typedef NS_ENUM(NSInteger, ENUM_TYPE_CACHE_STRATEGY)
  17. {
  18. CACHE_STRATEGY_FAST = 1, //极速
  19. CACHE_STRATEGY_SMOOTH = 2, //流畅
  20. CACHE_STRATEGY_AUTO = 3, //自动
  21. };
  22. #define CACHE_TIME_FAST 1
  23. #define CACHE_TIME_SMOOTH 5
  24. #define CACHE_TIME_AUTO_MIN 5
  25. #define CACHE_TIME_AUTO_MAX 10
  26. @interface BGTPlayController ()<UITextFieldDelegate, TXLivePlayListener>
  27. @end
  28. @implementation BGTPlayController
  29. {
  30. BOOL _bHWDec;
  31. UIButton *_btnPlayMode;
  32. UIButton *_btnHWDec;
  33. long long _trackingTouchTS;
  34. BOOL _startSeek;
  35. BOOL _videoPause;
  36. CGRect _videoWidgetFrame; // 改变videoWidget的frame时候记得对其重新进行赋值
  37. UIImageView *_loadingImageView;
  38. BOOL _appIsInterrupt;
  39. float _sliderValue;
  40. TX_Enum_PlayType _playType;
  41. long long _startPlayTS;
  42. NSString *_playDurationStr; // 播放时长
  43. // 普通播放配置
  44. TXLivePlayConfig *_txLivePlayConfig;
  45. TXLivePlayConfig *_rightTxLivePlayConfig;
  46. }
  47. - (void)dealloc
  48. {
  49. if (_play_switch == YES)
  50. {
  51. [self stopRtmp];
  52. }
  53. }
  54. - (void)viewDidLoad
  55. {
  56. [super viewDidLoad];
  57. if (self.playLiveType == FW_LIVE_TYPE_AUDIENCE) {
  58. _play_switch = NO;
  59. self.isLivePlay = YES;
  60. }
  61. [self initUI];
  62. }
  63. - (void)initUI
  64. {
  65. self.view.backgroundColor = [UIColor blackColor];
  66. _playDurationStr = @"00:00";
  67. _videoWidgetFrame = [UIScreen mainScreen].bounds;
  68. // remove all subview
  69. for (UIView *view in [self.view subviews])
  70. {
  71. [view removeFromSuperview];
  72. }
  73. CGSize size = [[UIScreen mainScreen] bounds].size;
  74. int icon_size = size.width / 10;
  75. _cover = [[UIView alloc]init];
  76. _cover.frame = CGRectMake(10.0f, 55 + 2*icon_size, size.width - 20, size.height - 75 - 3 * icon_size);
  77. _cover.backgroundColor = [UIColor grayColor];
  78. _cover.alpha = 0.5;
  79. _cover.hidden = YES;
  80. [self.view addSubview:_cover];
  81. int logheadH = 65;
  82. _statusView = [[UITextView alloc] initWithFrame:CGRectMake(10.0f, 55 + 2*icon_size, size.width - 20, logheadH)];
  83. _statusView.backgroundColor = [UIColor clearColor];
  84. _statusView.alpha = 1;
  85. _statusView.textColor = [UIColor blackColor];
  86. _statusView.editable = NO;
  87. _statusView.hidden = YES;
  88. [self.view addSubview:_statusView];
  89. _logViewEvt = [[UITextView alloc] initWithFrame:CGRectMake(10.0f, 55 + 2*icon_size + logheadH, size.width - 20, size.height - 75 - 3 * icon_size - logheadH)];
  90. _logViewEvt.backgroundColor = [UIColor clearColor];
  91. _logViewEvt.alpha = 1;
  92. _logViewEvt.textColor = [UIColor blackColor];
  93. _logViewEvt.editable = NO;
  94. _logViewEvt.hidden = YES;
  95. [self.view addSubview:_logViewEvt];
  96. int icon_length = 8;
  97. if (!self.isLivePlay)
  98. {
  99. icon_length = 6;
  100. }
  101. else
  102. {
  103. icon_length = 7;
  104. }
  105. int icon_gap = (size.width - icon_size*(icon_length-1))/icon_length;
  106. int btn_index = 0;
  107. _play_switch = NO;
  108. // 2019年08月24日
  109. _log_switch = YES;
  110. // [self createBottomBtnIndex:btn_index++ Icon:@"log" Action:@selector(clickLog:) Gap:icon_gap Size:icon_size];
  111. _bHWDec = NO;
  112. _btnHWDec = [self createBottomBtnIndex:btn_index++ Icon:@"quick2" Action:@selector(onClickHardware:) Gap:icon_gap Size:icon_size];
  113. _screenPortrait = NO;
  114. [self createBottomBtnIndex:btn_index++ Icon:@"portrait" Action:@selector(clickScreenOrientation:) Gap:icon_gap Size:icon_size];
  115. _renderFillScreen = YES;
  116. [self createBottomBtnIndex:btn_index++ Icon:@"adjust" Action:@selector(clickRenderMode:) Gap:icon_gap Size:icon_size];
  117. //极速直播
  118. if([self tentuCloudPlay])
  119. {
  120. _txLivePlayer = [[TXLivePlayer alloc] init];
  121. }
  122. // else
  123. // {
  124. //// [self initializeAgoraEngine];
  125. //
  126. //
  127. // }
  128. [TXLiveBase setLogLevel:LOGLEVEL_NULL];
  129. if (!self.isLivePlay)
  130. {
  131. _btnCacheStrategy = nil;
  132. }
  133. else
  134. {
  135. _btnCacheStrategy = [self createBottomBtnIndex:btn_index++ Icon:@"cache_time" Action:@selector(onAdjustCacheStrategy:) Gap:icon_gap Size:icon_size];
  136. }
  137. [self setCacheStrategy:CACHE_STRATEGY_AUTO];
  138. _videoPause = NO;
  139. _trackingTouchTS = 0;
  140. if (!self.isLivePlay)
  141. {
  142. _playStart.hidden = NO;
  143. _playProgress.hidden = NO;
  144. }
  145. else
  146. {
  147. _playStart.hidden = YES;
  148. _playProgress.hidden = YES;
  149. }
  150. //loading imageview
  151. float width = 34;
  152. float height = 34;
  153. float offsetX = (self.view.frame.size.width - width) / 2;
  154. float offsetY = (self.view.frame.size.height - height) / 2;
  155. NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"loading_image0.png"],[UIImage imageNamed:@"loading_image1.png"],[UIImage imageNamed:@"loading_image2.png"],[UIImage imageNamed:@"loading_image3.png"],[UIImage imageNamed:@"loading_image4.png"],[UIImage imageNamed:@"loading_image5.png"],[UIImage imageNamed:@"loading_image6.png"],[UIImage imageNamed:@"loading_image7.png"], nil];
  156. _loadingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(offsetX, offsetY, width, height)];
  157. _loadingImageView.animationImages = array;
  158. _loadingImageView.animationDuration = 1;
  159. _loadingImageView.hidden = YES;
  160. [self.view addSubview:_loadingImageView];
  161. //给声网用的
  162. _videoContrainerViewAgora = [[UIView alloc] initWithFrame:self.view.bounds];
  163. _videoContrainerViewAgora.hidden = YES;
  164. // _videoContrainerView.tag = 19967;//主播视图tag
  165. [self.view insertSubview:_videoContrainerViewAgora atIndex:0];
  166. _videoContrainerView = [[UIView alloc] initWithFrame:self.view.bounds];
  167. // _videoContrainerView.tag = 19967;//主播视图tag
  168. [self.view insertSubview:_videoContrainerView atIndex:0];
  169. if([GlobalVariables sharedInstance].openAgora)
  170. {
  171. // [self setupLocalVideo];
  172. // [self joinChannel];
  173. }
  174. _videoContrainerView.center = self.view.center;
  175. }
  176. //是否是腾讯云rtmp播放
  177. - (BOOL)tentuCloudPlay
  178. {
  179. return ![GlobalVariables sharedInstance].openAgora;
  180. }
  181. - (void)setPlayUrlStr:(NSString *)playUrlStr
  182. {
  183. _playUrlStr = playUrlStr;
  184. }
  185. #pragma -- example code bellow
  186. - (void)clearLog
  187. {
  188. _tipsMsg = @"";
  189. _logMsg = @"";
  190. [_statusView setText:@""];
  191. [_logViewEvt setText:@""];
  192. _startTime = [[NSDate date]timeIntervalSince1970]*1000;
  193. _lastTime = _startTime;
  194. }
  195. - (BOOL)checkPlayUrl:(NSString*)playUrl
  196. {
  197. #warning 暂时注释
  198. /*
  199. if (!([playUrl hasPrefix:@"http:"] || [playUrl hasPrefix:@"https:"] || [playUrl hasPrefix:@"rtmp:"]))
  200. {
  201. [self toastTip:ASLocalizedString(@"播放地址不合法,目前仅支持rtmp,flv,hls,mp4播放方式!")];
  202. return NO;
  203. }
  204. if (self.isLivePlay)
  205. {
  206. if ([playUrl hasPrefix:@"rtmp:"])
  207. {
  208. _playType = PLAY_TYPE_LIVE_RTMP;
  209. }
  210. else if (([playUrl hasPrefix:@"https:"] || [playUrl hasPrefix:@"http:"]))
  211. {
  212. if([playUrl containsString:@".flv"])
  213. {
  214. _playType = PLAY_TYPE_LIVE_FLV;
  215. }
  216. else if([playUrl containsString:@".mp4"])
  217. {
  218. _playType = PLAY_TYPE_VOD_MP4;
  219. }
  220. else if([playUrl containsString:@".m3u8"])
  221. {
  222. _playType = PLAY_TYPE_VOD_HLS;
  223. }
  224. else
  225. {
  226. [self toastTip:ASLocalizedString(@"播放地址不合法,直播目前仅支持flv,hls,mp4播放方式!")];
  227. return NO;
  228. }
  229. }
  230. else
  231. {
  232. [self toastTip:ASLocalizedString(@"播放地址不合法,直播目前仅支持rtmp,flv播放方式!")];
  233. return NO;
  234. }
  235. }
  236. else
  237. {
  238. if ([playUrl hasPrefix:@"https:"] || [playUrl hasPrefix:@"http:"])
  239. {
  240. if ([playUrl rangeOfString:@".flv"].length > 0)
  241. {
  242. _playType = PLAY_TYPE_VOD_FLV;
  243. }
  244. else if ([playUrl rangeOfString:@".m3u8"].length > 0)
  245. {
  246. _playType= PLAY_TYPE_VOD_HLS;
  247. }
  248. else if ([playUrl rangeOfString:@".mp4"].length > 0)
  249. {
  250. _playType= PLAY_TYPE_VOD_MP4;
  251. }
  252. else
  253. {
  254. [self toastTip:ASLocalizedString(@"播放地址不合法,点播目前仅支持flv,hls,mp4播放方式!")];
  255. return NO;
  256. }
  257. }
  258. else
  259. {
  260. [self toastTip:ASLocalizedString(@"播放地址不合法,点播目前仅支持flv,hls,mp4播放方式!")];
  261. return NO;
  262. }
  263. }
  264. */
  265. return YES;
  266. }
  267. - (BOOL)startRtmp:(NSInteger)create_type
  268. {
  269. // [self joinChannel];
  270. _create_type = create_type;
  271. NSString* playUrl = _playUrlStr;
  272. if (playUrl.length == 0)
  273. {
  274. playUrl = RTMP_URL;
  275. }
  276. if (![self checkPlayUrl:playUrl])
  277. {
  278. return NO;
  279. }
  280. [self clearLog];
  281. if(_txLivePlayer != nil)
  282. {
  283. _txLivePlayer.delegate = self;
  284. [_txLivePlayer setupVideoWidget:CGRectMake(0, 0, 0, 0) containView:_videoContrainerView insertIndex:0];
  285. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onPKViewChange:) name:@"onPKViewChange" object:nil];
  286. //设置播放器缓存策略
  287. //这里将播放器的策略设置为自动调整,调整的范围设定为1到4s,您也可以通过setCacheTime将播放器策略设置为采用
  288. //固定缓存时间。如果您什么都不调用,播放器将采用默认的策略(默认策略为自动调整,调整范围为1到4s)
  289. // [_txLivePlayer setCacheTime:5];
  290. // [_txLivePlayer setMinCacheTime:1];
  291. // [_txLivePlayer setMaxCacheTime:4];
  292. int result = [_txLivePlayer startLivePlay:playUrl type:_playType];
  293. NSLog(@"播放结果:%d, 播流地址 %@", result, playUrl);
  294. if (result == -1)
  295. {
  296. [self toastTip:ASLocalizedString(@"非腾讯云链接,若要放开限制请联系腾讯云商务团队")];
  297. return NO;
  298. }
  299. if( result != 0)
  300. {
  301. NSLog(ASLocalizedString(@"播放器启动失败"));
  302. return NO;
  303. }
  304. if (_screenPortrait)
  305. {
  306. [_txLivePlayer setRenderRotation:HOME_ORIENTATION_RIGHT];
  307. }
  308. else
  309. {
  310. [_txLivePlayer setRenderRotation:HOME_ORIENTATION_DOWN];
  311. }
  312. if (_renderFillScreen)
  313. {
  314. [_txLivePlayer setRenderMode:RENDER_MODE_FILL_SCREEN];
  315. }
  316. else
  317. {
  318. [_txLivePlayer setRenderMode:RENDER_MODE_FILL_EDGE];
  319. }
  320. if (_create_type == 1)
  321. {
  322. [_txLivePlayer setRenderMode:RENDER_MODE_FILL_EDGE];
  323. }
  324. else
  325. {
  326. [_txLivePlayer setRenderMode:RENDER_MODE_FILL_SCREEN];
  327. }
  328. // [_txLivePlayer setRenderMode:RENDER_MODE_FILL_SCREEN];
  329. // [_txLivePlayer setRenderMode:RENDER_MODE_FILL_EDGE];
  330. // [self startLoadingAnimation];
  331. _videoPause = NO;
  332. [_btnPlay setImage:[UIImage imageNamed:@"fw_relive_suspend"] forState:UIControlStateNormal];
  333. }
  334. if (_delegate && [_delegate respondsToSelector:@selector(firstFrame:)])
  335. {
  336. [_delegate firstFrame:self];
  337. _rePlayTime = 0;
  338. }
  339. _startPlayTS = [[NSDate date]timeIntervalSince1970]*1000;
  340. return YES;
  341. }
  342. - (void)initRightVideoContainerView{
  343. if (!_rightVideoContrainerView) {
  344. _rightVideoContrainerView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW / 2, kStatusBarHeight + 53 + 55, kScreenW / 2, kScreenW * 2 / 3)];
  345. _rightVideoContrainerView.backgroundColor = kBlackColor;
  346. }
  347. [self.view addSubview:_rightVideoContrainerView];
  348. }
  349. - (void)initTXLivePlayerWithUrl:(NSString *)playUrl playType:(NSInteger)playType{
  350. if (!_rightTxLivePlayer) {
  351. _rightTxLivePlayer = [[TXLivePlayer alloc] init];//初始化
  352. }
  353. if (!_rightTxLivePlayConfig) {
  354. _rightTxLivePlayConfig = [[TXLivePlayConfig alloc]init];
  355. _rightTxLivePlayConfig.enableAEC = YES;
  356. _rightTxLivePlayConfig.bAutoAdjustCacheTime = YES;
  357. _rightTxLivePlayConfig.minAutoAdjustCacheTime = CACHE_TIME_AUTO_MIN;
  358. _rightTxLivePlayConfig.maxAutoAdjustCacheTime = CACHE_TIME_AUTO_MAX;
  359. }
  360. [_rightTxLivePlayer setConfig:_rightTxLivePlayConfig];
  361. _rightTxLivePlayer.delegate = self; //如果您需要处理播放的事件
  362. [_rightTxLivePlayer setupVideoWidget:CGRectMake(0, 0, 0, 0) containView:_rightVideoContrainerView insertIndex:0];
  363. int result = [_rightTxLivePlayer startLivePlay:[self changeRTMPToFlv:playUrl] type:playType];
  364. if (result == -1)
  365. {
  366. [self toastTip:ASLocalizedString(@"非腾讯云链接,若要放开限制请联系腾讯云商务团队")];
  367. }
  368. if( result != 0)
  369. {
  370. NSLog(ASLocalizedString(@"播放器启动失败"));
  371. }
  372. }
  373. - (void)addVSView{
  374. //红蓝双方
  375. if (!redBgView) {
  376. redBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW / 2, kScreenH)];
  377. redBgView.backgroundColor = [UIColor colorWithHexString:@"#731a5a"];
  378. [self.view addSubview:redBgView];
  379. [self.view sendSubviewToBack:redBgView];
  380. }else{
  381. [self.view addSubview:redBgView];
  382. [self.view sendSubviewToBack:redBgView];
  383. }
  384. if (!blueBgView) {
  385. blueBgView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW / 2, 0, kScreenW / 2, kScreenH)];
  386. blueBgView.backgroundColor = [UIColor colorWithHexString:@"#012e89"];
  387. [self.view addSubview:blueBgView];
  388. [self.view sendSubviewToBack:blueBgView];
  389. }else{
  390. [self.view addSubview:blueBgView];
  391. [self.view sendSubviewToBack:blueBgView];
  392. }
  393. }
  394. - (void)addPkBgView{
  395. if (!_pkBgView) {
  396. _pkBgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  397. _pkBgView.image = [UIImage imageNamed:@"pk_bg"];
  398. }
  399. [self.view addSubview:_pkBgView];
  400. [self.view sendSubviewToBack:_pkBgView];
  401. }
  402. //该参数就是发送过来的通知,接到通知后执行的方法
  403. - (void)onPKViewChange:(NSNotification *)notify
  404. {
  405. int isFull = [[notify.userInfo valueForKey:@"isFull"] intValue];
  406. NSString *playUrl = [notify.userInfo valueForKey:@"playUrl"];
  407. TX_Enum_PlayType _playType = PLAY_TYPE_LIVE_RTMP;
  408. if ([playUrl hasPrefix:@"rtmp:"])
  409. {
  410. _playType = PLAY_TYPE_LIVE_RTMP;
  411. }
  412. else if (([playUrl hasPrefix:@"https:"] || [playUrl hasPrefix:@"http:"]) && [playUrl rangeOfString:@".flv"].length > 0)
  413. {
  414. _playType = PLAY_TYPE_LIVE_FLV;
  415. }
  416. // _playType = PLAY_TYPE_LIVE_RTMP_ACC;
  417. if(isFull == 1)
  418. {
  419. //模拟动态修改
  420. _videoContrainerView.frame = self.view.bounds;
  421. [redBgView removeFromSuperview];
  422. [blueBgView removeFromSuperview];
  423. // [pkBgView removeFromSuperview];
  424. _rightTxLivePlayer.delegate = nil;
  425. [_rightTxLivePlayer stopPlay];
  426. [_rightTxLivePlayer removeVideoWidget];
  427. _rightTxLivePlayer = nil;
  428. [_rightVideoContrainerView removeFromSuperview];
  429. _rightVideoContrainerView = nil;
  430. float width = 34;
  431. float height = 34;
  432. float offsetX = (self.view.frame.size.width - width) / 2;
  433. float offsetY = (self.view.frame.size.height - height) / 2;
  434. _loadingImageView.frame = CGRectMake(offsetX, offsetY, width, height);
  435. [self stopLoadingAnimation];
  436. [GlobalVariables sharedInstance].isBeingPK = NO;
  437. NSString* playUrl = _playUrlStr;
  438. if([playUrl isEqualToString:[_txLivePlayer valueForKey:@"_playUrl"]])
  439. {
  440. int result = [_txLivePlayer startLivePlay:playUrl type:_playType];
  441. NSLog(@"播流状态 %d",result);
  442. }
  443. [self.txLivePlayer stopPlay];
  444. self.videoContrainerViewAgora.hidden = YES;
  445. #warning 暂时注释,后续确认是否需要
  446. // [self.agoraKit enableVideo];
  447. // [self.agoraKit enableAudio];
  448. }
  449. else if(isFull == 3)
  450. {
  451. if(![GlobalVariables sharedInstance].openAgora)
  452. {
  453. // _videoContrainerView.frame = CGRectMake(0, kStatusBarHeight + 53 + 55, kScreenW / 2, kScreenW * 2 / 3);
  454. // // _videoContrainerView.frame = CGRectMake(0, 0, kScreenW/2, kScreenH/2);
  455. // [self addPkBgView];
  456. // [self initRightVideoContainerView];
  457. // [self initTXLivePlayerWithUrl:playUrl playType:_playType];
  458. // _loadingImageView.centerX = _rightVideoContrainerView.centerX;
  459. // _loadingImageView.centerY = _rightVideoContrainerView.centerY;
  460. //
  461. // [GlobalVariables sharedInstance].isBeingPK = YES;
  462. //
  463. // _videoContrainerViewAgora.hidden = NO;
  464. // [_txLivePlayer setupVideoWidget:CGRectMake(0, 0, 0, 0) containView:_videoContrainerViewAgora insertIndex:0];
  465. //
  466. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onPKViewChange:) name:@"onPKViewChange" object:nil];
  467. // [_txLivePlayer startPlay:_playUrlStr type:_playType];
  468. //设置播放器缓存策略
  469. //这里将播放器的策略设置为自动调整,调整的范围设定为1到4s,您也可以通过setCacheTime将播放器策略设置为采用
  470. //固定缓存时间。如果您什么都不调用,播放器将采用默认的策略(默认策略为自动调整,调整范围为1到4s)
  471. //[_txLivePlayer setCacheTime:5];
  472. //[_txLivePlayer setMinCacheTime:1];
  473. //[_txLivePlayer setMaxCacheTime:4];
  474. // int result = [_txLivePlayer startPlay:playUrl type:_playType];
  475. }
  476. else
  477. {
  478. BogoPkProgressModel *model = [notify.userInfo valueForKey:@"model"];
  479. NSInteger imUserId = [IMAPlatform sharedInstance].host.imUserId.integerValue;
  480. NSString *playRtmp = @"";
  481. if(model.emcee_user_id1.intValue == imUserId)
  482. {
  483. playRtmp = model.play_url1;
  484. }
  485. else
  486. {
  487. playRtmp = model.play_url2;
  488. }
  489. // [_txLivePlayer startPlay:playRtmp type:_playType];
  490. _videoContrainerView.frame = CGRectMake(0, kStatusBarHeight + 53 + 55, kScreenW / 2, kScreenW * 2 / 3);
  491. // _videoContrainerView.frame = CGRectMake(0, 0, kScreenW/2, kScreenH/2);
  492. [self addPkBgView];
  493. [self initRightVideoContainerView];
  494. // [self initTXLivePlayerWithUrl:playUrl playType:_playType];
  495. // [_txLivePlayer setupVideoWidget:CGRectMake(0, 0, 0, 0) containView:_videoContrainerViewAgora insertIndex:0];
  496. //关闭声网音视频
  497. // [self.agoraKit disableVideo];
  498. // [self.agoraKit disableAudio];
  499. _videoContrainerViewAgora.hidden = NO;
  500. _loadingImageView.centerX = _rightVideoContrainerView.centerX;
  501. _loadingImageView.centerY = _rightVideoContrainerView.centerY;
  502. [GlobalVariables sharedInstance].isBeingPK = YES;
  503. }
  504. }
  505. else if(isFull == 0)
  506. {
  507. // _videoContrainerView.frame = CGRectMake(kScreenW/2, 0, kScreenW/2, kScreenH/2);
  508. _videoContrainerView.frame = CGRectMake(0, kStatusBarHeight + 53 + 55, kScreenW / 2, kScreenW * 2 / 3);
  509. [self addPkBgView];
  510. [self initRightVideoContainerView];
  511. [self initTXLivePlayerWithUrl:playUrl playType:_playType];
  512. _loadingImageView.centerX = _rightVideoContrainerView.centerX;
  513. _loadingImageView.centerY = _rightVideoContrainerView.centerY;
  514. [GlobalVariables sharedInstance].isBeingPK = YES;
  515. }
  516. }
  517. - (void)stopRtmp
  518. {
  519. // [self.agoraKit leaveChannel:nil];
  520. [self stopLoadingAnimation];
  521. if(_txLivePlayer != nil)
  522. {
  523. _txLivePlayer.delegate = nil;
  524. [_txLivePlayer stopPlay];
  525. [_txLivePlayer removeVideoWidget];
  526. }
  527. if (_rightTxLivePlayer != nil) {
  528. _rightTxLivePlayer.delegate = nil;
  529. [_rightTxLivePlayer stopPlay];
  530. [_rightTxLivePlayer removeVideoWidget];
  531. }
  532. }
  533. - (void)rePlay
  534. {
  535. if (_delegate && [_delegate respondsToSelector:@selector(playAgain:isHideLeaveTip:)])
  536. {
  537. [_delegate playAgain:self isHideLeaveTip:NO];
  538. }
  539. }
  540. #pragma mark - ----------------------- TXLivePlayListener代理事件 -----------------------
  541. - (void)onPlayEvent:(int)EvtID withParam:(NSDictionary*)param;
  542. {
  543. if (EvtID != PLAY_EVT_PLAY_PROGRESS)
  544. {
  545. NSLog(@"==========playEvtID1:%d",EvtID);
  546. }
  547. NSDictionary* dict = param;
  548. dispatch_async(dispatch_get_main_queue(), ^{
  549. if (EvtID == PLAY_EVT_RCV_FIRST_I_FRAME)
  550. {
  551. if (_delegate && [_delegate respondsToSelector:@selector(firstFrame:)])
  552. {
  553. [_delegate firstFrame:self];
  554. _rePlayTime = 0;
  555. }
  556. [self stopLoadingAnimation];
  557. }
  558. else if (EvtID == PLAY_EVT_PLAY_BEGIN)
  559. {
  560. [self stopLoadingAnimation];
  561. long long playDelay = [[NSDate date]timeIntervalSince1970]*1000 - _startPlayTS;
  562. NSLog(@"AutoMonitor:PlayFirstRender,cost=%lld", playDelay);
  563. }
  564. else if (EvtID == PLAY_EVT_PLAY_PROGRESS && !_startSeek)
  565. {
  566. // 避免滑动进度条松开的瞬间可能出现滑动条瞬间跳到上一个位置
  567. long long curTs = [[NSDate date]timeIntervalSince1970]*1000;
  568. if (llabs(curTs - _trackingTouchTS) < 500) {
  569. return;
  570. }
  571. _trackingTouchTS = curTs;
  572. float progress = [dict[EVT_PLAY_PROGRESS] floatValue];
  573. int intProgress = progress + 0.5;
  574. _playStart.text = [[NSString stringWithFormat:@"%02d:%02d", (int)(intProgress / 60), (int)(intProgress % 60)] stringByAppendingString:[NSString stringWithFormat:@"/%@",_playDurationStr]];
  575. [_playProgress setValue:progress];
  576. float duration = [dict[EVT_PLAY_DURATION] floatValue];
  577. int intDuration = duration + 0.5;
  578. if (duration > 0 && _playProgress.maximumValue != duration) {
  579. [_playProgress setMaximumValue:duration];
  580. _playDurationStr = [NSString stringWithFormat:@"%02d:%02d", (int)(intDuration / 60), (int)(intDuration % 60)];
  581. }
  582. return ;
  583. }
  584. else if (EvtID == PLAY_ERR_NET_DISCONNECT)
  585. {
  586. [self stopRtmp];
  587. _play_switch = NO;
  588. [_btnPlay setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
  589. [_playProgress setValue:0];
  590. _playStart.text = @"00:00/00:00";
  591. _videoPause = NO;
  592. [self performSelector:@selector(rePlay) withObject:nil afterDelay:3];
  593. }
  594. else if (EvtID == PLAY_EVT_PLAY_END)
  595. {
  596. [_txLivePlayer pause];
  597. [_btnPlay setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
  598. }
  599. else if (EvtID == PLAY_EVT_PLAY_LOADING)
  600. {
  601. // [self startLoadingAnimation];
  602. }
  603. long long time = [(NSNumber*)[dict valueForKey:EVT_TIME] longLongValue];
  604. int mil = time % 1000;
  605. NSDate* date = [NSDate dateWithTimeIntervalSince1970:time/1000];
  606. NSString* Msg = (NSString*)[dict valueForKey:EVT_MSG];
  607. [self appendLog:Msg time:date mills:mil];
  608. });
  609. }
  610. - (void)onNetStatus:(NSDictionary*) param
  611. {
  612. NSDictionary* dict = param;
  613. _qualityDict = param;
  614. /*
  615. dispatch_async(dispatch_get_main_queue(), ^{
  616. int netspeed = [(NSNumber*)[dict valueForKey:NET_STATUS_NET_SPEED] intValue];
  617. int vbitrate = [(NSNumber*)[dict valueForKey:NET_STATUS_VIDEO_BITRATE] intValue];
  618. int settrate = [(NSNumber*)[dict valueForKey:NET_STATUS_SET_VIDEO_BITRATE] intValue];
  619. _kbpsRecvStr = StringFromInt(vbitrate);
  620. _kbpsSendStr = StringFromInt(settrate);
  621. int abitrate = [(NSNumber*)[dict valueForKey:NET_STATUS_AUDIO_BITRATE] intValue];
  622. int cachesize = [(NSNumber*)[dict valueForKey:NET_STATUS_CACHE_SIZE] intValue];
  623. int dropsize = [(NSNumber*)[dict valueForKey:NET_STATUS_DROP_SIZE] intValue];
  624. int jitter = [(NSNumber*)[dict valueForKey:NET_STATUS_NET_JITTER] intValue];
  625. int fps = [(NSNumber*)[dict valueForKey:NET_STATUS_VIDEO_FPS] intValue];
  626. int width = [(NSNumber*)[dict valueForKey:NET_STATUS_VIDEO_WIDTH] intValue];
  627. int height = [(NSNumber*)[dict valueForKey:NET_STATUS_VIDEO_HEIGHT] intValue];
  628. float cpu_usage = [(NSNumber*)[dict valueForKey:NET_STATUS_CPU_USAGE] floatValue];
  629. NSString *serverIP = [dict valueForKey:NET_STATUS_SERVER_IP];
  630. int codecCacheSize = [(NSNumber*)[dict valueForKey:NET_STATUS_CODEC_CACHE] intValue];
  631. int nCodecDropCnt = [(NSNumber*)[dict valueForKey:NET_STATUS_CODEC_DROP_CNT] intValue];
  632. NSString* log = [NSString stringWithFormat:@"CPU:%.1f%%\tRES:%d*%d\tSPD:%dkb/s\nJITT:%d\tFPS:%d\tARA:%dkb/s\nQUE:%d|%d\tDRP:%d|%d\tVRA:%dkb/s\nSVR:%@\t",
  633. cpu_usage*100,
  634. width,
  635. height,
  636. netspeed,
  637. jitter,
  638. fps,
  639. abitrate,
  640. codecCacheSize,
  641. cachesize,
  642. nCodecDropCnt,
  643. dropsize,
  644. vbitrate,
  645. serverIP];
  646. [_statusView setText:log];
  647. });
  648. */
  649. }
  650. - (void)startLoadingAnimation
  651. {
  652. if (_loadingImageView != nil)
  653. {
  654. _loadingImageView.hidden = NO;
  655. [_loadingImageView startAnimating];
  656. }
  657. }
  658. - (void)stopLoadingAnimation
  659. {
  660. if (_loadingImageView != nil)
  661. {
  662. _loadingImageView.hidden = YES;
  663. [_loadingImageView stopAnimating];
  664. }
  665. }
  666. #pragma ###TXLivePlayListener
  667. - (void)appendLog:(NSString*) evt time:(NSDate*) date mills:(int)mil
  668. {
  669. if (evt == nil)
  670. {
  671. return;
  672. }
  673. NSDateFormatter* format = [[NSDateFormatter alloc] init];
  674. format.dateFormat = @"hh:mm:ss";
  675. NSString* time = [format stringFromDate:date];
  676. NSString* log = [NSString stringWithFormat:@"[%@.%-3.3d] %@", time, mil, evt];
  677. if (_logMsg == nil) {
  678. _logMsg = @"";
  679. }
  680. _logMsg = [NSString stringWithFormat:@"%@\n%@", _logMsg, log ];
  681. [_logViewEvt setText:_logMsg];
  682. }
  683. #pragma mark - ----------------------- 底部按钮事件 -----------------------
  684. #pragma mark 点击播放按钮
  685. - (void)clickPlay:(UIButton *)sender create_type:(NSInteger)create_type
  686. {
  687. #warning 暂时注释
  688. /*
  689. _create_type = create_type;
  690. if (_play_switch == YES)
  691. {
  692. if (_playType == PLAY_TYPE_VOD_FLV || _playType == PLAY_TYPE_VOD_HLS || _playType == PLAY_TYPE_VOD_MP4)
  693. {
  694. if (_videoPause)
  695. {
  696. [_txLivePlayer resume];
  697. [sender setImage:[UIImage imageNamed:@"fw_relive_suspend"] forState:UIControlStateNormal];
  698. }
  699. else
  700. {
  701. [_txLivePlayer pause];
  702. [sender setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
  703. }
  704. _videoPause = !_videoPause;
  705. }
  706. else
  707. {
  708. _play_switch = NO;
  709. [self stopRtmp];
  710. [sender setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
  711. }
  712. }
  713. else
  714. {
  715. if (![self startRtmp:create_type])
  716. {
  717. return;
  718. }
  719. [sender setImage:[UIImage imageNamed:@"fw_relive_suspend"] forState:UIControlStateNormal];
  720. _play_switch = YES;
  721. }
  722. */
  723. }
  724. #pragma mark 点击日志按钮
  725. - (void)clickLog:(UIButton*) sender
  726. {
  727. // if (_log_switch == YES)
  728. // {
  729. // _statusView.hidden = YES;
  730. // _logViewEvt.hidden = YES;
  731. // [sender setImage:[UIImage imageNamed:@"log"] forState:UIControlStateNormal];
  732. // _cover.hidden = YES;
  733. // _log_switch = NO;
  734. // }
  735. // else
  736. // {
  737. // _statusView.hidden = NO;
  738. // _logViewEvt.hidden = NO;
  739. // [sender setImage:[UIImage imageNamed:@"log2"] forState:UIControlStateNormal];
  740. // _cover.hidden = NO;
  741. // _log_switch = YES;
  742. // }
  743. //// 2019年08月24日
  744. // sender.hidden = YES;
  745. }
  746. #pragma mark 点击横竖屏按钮
  747. - (void) clickScreenOrientation:(UIButton*) sender
  748. {
  749. _screenPortrait = !_screenPortrait;
  750. if (_screenPortrait)
  751. {
  752. [sender setImage:[UIImage imageNamed:@"landscape"] forState:UIControlStateNormal];
  753. [_txLivePlayer setRenderRotation:HOME_ORIENTATION_RIGHT];
  754. }
  755. else
  756. {
  757. [sender setImage:[UIImage imageNamed:@"portrait"] forState:UIControlStateNormal];
  758. [_txLivePlayer setRenderRotation:HOME_ORIENTATION_DOWN];
  759. }
  760. }
  761. #pragma mark 点击填充模式按钮
  762. - (void) clickRenderMode:(UIButton*) sender
  763. {
  764. _renderFillScreen = !_renderFillScreen;
  765. if (_renderFillScreen) {
  766. [sender setImage:[UIImage imageNamed:@"adjust"] forState:UIControlStateNormal];
  767. [_txLivePlayer setRenderMode:RENDER_MODE_FILL_SCREEN];
  768. } else {
  769. [sender setImage:[UIImage imageNamed:@"fill"] forState:UIControlStateNormal];
  770. [_txLivePlayer setRenderMode:RENDER_MODE_FILL_EDGE];
  771. }
  772. }
  773. #pragma mark 点击硬件加速按钮
  774. - (void) onClickHardware:(UIButton*)sender
  775. {
  776. if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
  777. [self toastTip:ASLocalizedString(@"iOS 版本低于8.0,不支持硬件加速.")];
  778. return;
  779. }
  780. if (_play_switch == YES)
  781. {
  782. [self stopRtmp];
  783. }
  784. _txLivePlayer.enableHWAcceleration = !_bHWDec;
  785. _bHWDec = _txLivePlayer.enableHWAcceleration;
  786. if(_bHWDec)
  787. {
  788. [sender setImage:[UIImage imageNamed:@"quick"] forState:UIControlStateNormal];
  789. }
  790. else
  791. {
  792. [sender setImage:[UIImage imageNamed:@"quick2"] forState:UIControlStateNormal];
  793. }
  794. if (_play_switch == YES) {
  795. if (_bHWDec) {
  796. [self toastTip:ASLocalizedString(@"切换为硬解码. 重启播放流程")];
  797. }
  798. else
  799. {
  800. [self toastTip:ASLocalizedString(@"切换为软解码. 重启播放流程")];
  801. }
  802. [self startRtmp:_create_type];
  803. }
  804. }
  805. #pragma mark UISlider代理方法
  806. - (void)onSeek:(UISlider *)slider
  807. {
  808. #warning 暂时注释
  809. // [_txLivePlayer seek:_sliderValue];
  810. _trackingTouchTS = [[NSDate date]timeIntervalSince1970]*1000;
  811. _startSeek = NO;
  812. NSLog(@"vod seek drag end");
  813. }
  814. - (void)onSeekBegin:(UISlider *)slider
  815. {
  816. _startSeek = YES;
  817. NSLog(@"vod seek drag begin");
  818. }
  819. - (void)onDrag:(UISlider *)slider
  820. {
  821. float progress = slider.value;
  822. int intProgress = progress + 0.5;
  823. _playStart.text = [[NSString stringWithFormat:@"%02d:%02d",(int)(intProgress / 60), (int)(intProgress % 60)] stringByAppendingString:[NSString stringWithFormat:@"/%@",_playDurationStr]];
  824. _sliderValue = slider.value;
  825. }
  826. - (void)dragSliderDidEnd:(UISlider *)slider
  827. {
  828. _startSeek = NO;
  829. }
  830. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  831. {
  832. _vCacheStrategy.hidden = YES;
  833. }
  834. #pragma mark - ----------------------- 清晰度设置 -----------------------
  835. - (void) setCacheStrategy:(NSInteger) nCacheStrategy
  836. {
  837. if (_btnCacheStrategy == nil || _cacheStrategy == nCacheStrategy) return;
  838. if (_txLivePlayConfig == nil)
  839. {
  840. _txLivePlayConfig = [[TXLivePlayConfig alloc] init];
  841. _txLivePlayConfig.enableAEC = YES;
  842. }
  843. _cacheStrategy = nCacheStrategy;
  844. switch (_cacheStrategy) {
  845. case CACHE_STRATEGY_FAST:
  846. _txLivePlayConfig.bAutoAdjustCacheTime = YES;
  847. _txLivePlayConfig.minAutoAdjustCacheTime = CACHE_TIME_FAST;
  848. _txLivePlayConfig.maxAutoAdjustCacheTime = CACHE_TIME_FAST;
  849. [_txLivePlayer setConfig:_txLivePlayConfig];
  850. break;
  851. case CACHE_STRATEGY_SMOOTH:
  852. _txLivePlayConfig.bAutoAdjustCacheTime = NO;
  853. _txLivePlayConfig.cacheTime = CACHE_TIME_SMOOTH;
  854. [_txLivePlayer setConfig:_txLivePlayConfig];
  855. break;
  856. case CACHE_STRATEGY_AUTO:
  857. _txLivePlayConfig.bAutoAdjustCacheTime = YES;
  858. _txLivePlayConfig.minAutoAdjustCacheTime = CACHE_TIME_AUTO_MIN;
  859. _txLivePlayConfig.maxAutoAdjustCacheTime = CACHE_TIME_AUTO_MAX;
  860. [_txLivePlayer setConfig:_txLivePlayConfig];
  861. break;
  862. default:
  863. break;
  864. }
  865. }
  866. - (void) onAdjustCacheStrategy:(UIButton*) sender
  867. {
  868. #if TEST_MUTE
  869. static BOOL flag = YES;
  870. [_txLivePlayer setMute:flag];
  871. flag = !flag;
  872. #else
  873. if (_vCacheStrategy == nil)
  874. {
  875. CGSize size = [[UIScreen mainScreen] bounds].size;
  876. _vCacheStrategy = [[UIControl alloc]init];
  877. _vCacheStrategy.frame = CGRectMake(0, size.height-120, size.width, 120);
  878. [_vCacheStrategy setBackgroundColor:[UIColor whiteColor]];
  879. UILabel* title= [[UILabel alloc]init];
  880. title.frame = CGRectMake(0, 0, size.width, 50);
  881. [title setText:ASLocalizedString(@"缓存策略")];
  882. title.textAlignment = NSTextAlignmentCenter;
  883. [title setFont:[UIFont fontWithName:@"" size:14]];
  884. [_vCacheStrategy addSubview:title];
  885. int gap = 30;
  886. int width = (size.width - gap*2 - 20) / 3;
  887. _radioBtnFast = [UIButton buttonWithType:UIButtonTypeCustom];
  888. _radioBtnFast.frame = CGRectMake(10, 60, width, 40);
  889. [_radioBtnFast setTitle:ASLocalizedString(@"极速")forState:UIControlStateNormal];
  890. [_radioBtnFast addTarget:self action:@selector(onAdjustFast:) forControlEvents:UIControlEventTouchUpInside];
  891. _radioBtnSmooth = [UIButton buttonWithType:UIButtonTypeCustom];
  892. _radioBtnSmooth.frame = CGRectMake(10 + gap + width, 60, width, 40);
  893. [_radioBtnSmooth setTitle:ASLocalizedString(@"流畅")forState:UIControlStateNormal];
  894. [_radioBtnSmooth addTarget:self action:@selector(onAdjustSmooth:) forControlEvents:UIControlEventTouchUpInside];
  895. _radioBtnAUTO = [UIButton buttonWithType:UIButtonTypeCustom];
  896. _radioBtnAUTO.frame = CGRectMake(size.width - 10 - width, 60, width, 40);
  897. [_radioBtnAUTO setTitle:ASLocalizedString(@"自动")forState:UIControlStateNormal];
  898. [_radioBtnAUTO addTarget:self action:@selector(onAdjustAuto:) forControlEvents:UIControlEventTouchUpInside];
  899. [_vCacheStrategy addSubview:_radioBtnFast];
  900. [_vCacheStrategy addSubview:_radioBtnSmooth];
  901. [_vCacheStrategy addSubview:_radioBtnAUTO];
  902. [self.view addSubview:_vCacheStrategy];
  903. }
  904. _vCacheStrategy.hidden = NO;
  905. switch (_cacheStrategy) {
  906. case CACHE_STRATEGY_FAST:
  907. [_radioBtnFast setBackgroundImage:[UIImage imageNamed:@"black"] forState:UIControlStateNormal];
  908. [_radioBtnFast setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  909. [_radioBtnSmooth setBackgroundImage:[UIImage imageNamed:@"white"] forState:UIControlStateNormal];
  910. [_radioBtnSmooth setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  911. [_radioBtnAUTO setBackgroundImage:[UIImage imageNamed:@"white"] forState:UIControlStateNormal];
  912. [_radioBtnAUTO setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  913. break;
  914. case CACHE_STRATEGY_SMOOTH:
  915. [_radioBtnFast setBackgroundImage:[UIImage imageNamed:@"white"] forState:UIControlStateNormal];
  916. [_radioBtnFast setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  917. [_radioBtnSmooth setBackgroundImage:[UIImage imageNamed:@"black"] forState:UIControlStateNormal];
  918. [_radioBtnSmooth setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  919. [_radioBtnAUTO setBackgroundImage:[UIImage imageNamed:@"white"] forState:UIControlStateNormal];
  920. [_radioBtnAUTO setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  921. break;
  922. case CACHE_STRATEGY_AUTO:
  923. [_radioBtnFast setBackgroundImage:[UIImage imageNamed:@"white"] forState:UIControlStateNormal];
  924. [_radioBtnFast setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  925. [_radioBtnSmooth setBackgroundImage:[UIImage imageNamed:@"white"] forState:UIControlStateNormal];
  926. [_radioBtnSmooth setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  927. [_radioBtnAUTO setBackgroundImage:[UIImage imageNamed:@"black"] forState:UIControlStateNormal];
  928. [_radioBtnAUTO setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  929. break;
  930. default:
  931. break;
  932. }
  933. #endif
  934. }
  935. - (void) onAdjustFast:(UIButton*) sender
  936. {
  937. _vCacheStrategy.hidden = YES;
  938. [self setCacheStrategy:CACHE_STRATEGY_FAST];
  939. }
  940. - (void) onAdjustSmooth:(UIButton*) sender
  941. {
  942. _vCacheStrategy.hidden = YES;
  943. [self setCacheStrategy:CACHE_STRATEGY_SMOOTH];
  944. }
  945. - (void) onAdjustAuto:(UIButton*) sender
  946. {
  947. _vCacheStrategy.hidden = YES;
  948. [self setCacheStrategy:CACHE_STRATEGY_AUTO];
  949. }
  950. #pragma mark - ----------------------- 进入前后台 -----------------------
  951. - (void)onAppDidEnterBackGround
  952. {
  953. #warning 暂时注释
  954. /*
  955. if (_play_switch == YES && _appIsInterrupt == NO)
  956. {
  957. if (_playType == PLAY_TYPE_VOD_FLV || _playType == PLAY_TYPE_VOD_HLS || _playType == PLAY_TYPE_VOD_MP4)
  958. {
  959. if (!_videoPause)
  960. {
  961. [_txLivePlayer pause];
  962. }
  963. }
  964. _appIsInterrupt = YES;
  965. }
  966. */
  967. }
  968. - (void)onAppWillEnterForeground
  969. {
  970. #warning 暂时注释
  971. /*
  972. if (_play_switch == YES && _appIsInterrupt == YES)
  973. {
  974. if (_playType == PLAY_TYPE_VOD_FLV || _playType == PLAY_TYPE_VOD_HLS || _playType == PLAY_TYPE_VOD_MP4)
  975. {
  976. if (!_videoPause)
  977. {
  978. [_txLivePlayer resume];
  979. }
  980. }
  981. _appIsInterrupt = NO;
  982. }
  983. */
  984. }
  985. #pragma mark - ----------------------- 声音打断监听 -----------------------
  986. - (void)onAudioInterruption:(NSNotification *)notification
  987. {
  988. #warning 暂时注释
  989. /*
  990. NSDictionary *info = notification.userInfo;
  991. AVAudioSessionInterruptionType type = [info[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
  992. if (type == AVAudioSessionInterruptionTypeBegan)
  993. {
  994. if (_play_switch == YES && _appIsInterrupt == NO)
  995. {
  996. if (_playType == PLAY_TYPE_VOD_FLV || _playType == PLAY_TYPE_VOD_HLS || _playType == PLAY_TYPE_VOD_MP4)
  997. {
  998. if (!_videoPause)
  999. {
  1000. [_txLivePlayer pause];
  1001. }
  1002. }
  1003. _appIsInterrupt = YES;
  1004. }
  1005. }
  1006. else
  1007. {
  1008. AVAudioSessionInterruptionOptions options = [info[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
  1009. if (options == AVAudioSessionInterruptionOptionShouldResume)
  1010. {
  1011. if (_play_switch == YES && _appIsInterrupt == YES)
  1012. {
  1013. if (_playType == PLAY_TYPE_VOD_FLV || _playType == PLAY_TYPE_VOD_HLS || _playType == PLAY_TYPE_VOD_MP4)
  1014. {
  1015. if (!_videoPause)
  1016. {
  1017. [_txLivePlayer resume];
  1018. }
  1019. }
  1020. _appIsInterrupt = NO;
  1021. }
  1022. }
  1023. }
  1024. */
  1025. }
  1026. #pragma mark - ----------------------- 自定义Toast -----------------------
  1027. /**
  1028. 获取指定宽度width的字符串在UITextView上的高度
  1029. @param textView 待计算的UITextView
  1030. @param width 限制字符串显示区域的宽度
  1031. @return 返回的高度
  1032. */
  1033. - (float)heightForString:(UITextView *)textView andWidth:(float)width
  1034. {
  1035. CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
  1036. return sizeToFit.height;
  1037. }
  1038. - (void)toastTip:(NSString*)toastInfo
  1039. {
  1040. NSLog(@"======playtoastInfo:%@",toastInfo);
  1041. CGRect frameRC = [[UIScreen mainScreen] bounds];
  1042. frameRC.origin.y = frameRC.size.height - 110;
  1043. frameRC.size.height -= 110;
  1044. __block UITextView * toastView = [[UITextView alloc] init];
  1045. toastView.editable = NO;
  1046. toastView.selectable = NO;
  1047. frameRC.size.height = [self heightForString:toastView andWidth:frameRC.size.width];
  1048. toastView.frame = frameRC;
  1049. toastView.text = toastInfo;
  1050. toastView.backgroundColor = [UIColor whiteColor];
  1051. toastView.alpha = 0.5;
  1052. [self.view addSubview:toastView];
  1053. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC);
  1054. dispatch_after(popTime, dispatch_get_main_queue(), ^(){
  1055. [toastView removeFromSuperview];
  1056. toastView = nil;
  1057. });
  1058. }
  1059. //6-19 修改-onPKViewChange
  1060. -(void)viewWillAppear:(BOOL)animated{
  1061. [super viewWillAppear:animated];
  1062. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onPKViewChange:) name:@"onPKViewChange" object:nil];
  1063. }
  1064. - (void)viewWillDisappear:(BOOL)animated {
  1065. [super viewWillDisappear:animated];
  1066. [[NSNotificationCenter defaultCenter]removeObserver:self name:@"onPKViewChange" object:nil];
  1067. }
  1068. #pragma mark - ----------------------- 创建按钮 -----------------------
  1069. - (UIButton*)createBottomBtnIndex:(int)index Icon:(NSString*)icon Action:(SEL)action Gap:(int)gap Size:(int)size
  1070. {
  1071. UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
  1072. btn.frame = CGRectMake((index+1)*gap + index*size, [[UIScreen mainScreen] bounds].size.height - size - 10, size, size);
  1073. [btn setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
  1074. [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
  1075. [self.view addSubview:btn];
  1076. return btn;
  1077. }
  1078. - (NSString *)changeRTMPToFlv:(NSString *)originalString{
  1079. NSMutableString *mStr = [NSMutableString stringWithString:originalString];
  1080. // [mStr replaceCharactersInRange:NSMakeRange(0, 4) withString:@"http"];
  1081. // [mStr appendString:@".flv"];
  1082. return mStr;
  1083. }
  1084. @end