BGTLinkMicPlayItem.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // BGTLinkMicPlayItem.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 2017/1/20.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGTLinkMicPlayItem.h"
  9. @implementation BGTLinkMicPlayItem
  10. - (void)initLoadingView:(UIView*)view
  11. {
  12. CGRect rect = view.frame;
  13. if (_loadingBackground == nil)
  14. {
  15. _loadingBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(rect), CGRectGetHeight(rect))];
  16. _loadingBackground.hidden = YES;
  17. _loadingBackground.backgroundColor = [UIColor blackColor];
  18. _loadingBackground.alpha = 0.5;
  19. [view addSubview:_loadingBackground];
  20. if (_loadingTextView == nil)
  21. {
  22. _loadingTextView = [[UITextView alloc]init];
  23. _loadingTextView.bounds = CGRectMake(0, 0, CGRectGetWidth(rect), 30);
  24. _loadingTextView.center = CGPointMake(CGRectGetWidth(rect) / 2, CGRectGetHeight(rect) / 2 - 30);
  25. _loadingTextView.textAlignment = NSTextAlignmentCenter;
  26. _loadingTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  27. _loadingTextView.textColor = [UIColor blackColor];
  28. _loadingTextView.text = ASLocalizedString(@"连麦中···");
  29. _loadingTextView.hidden = YES;
  30. [_loadingBackground addSubview:_loadingTextView];
  31. }
  32. }
  33. if (_loadingImageView == nil)
  34. {
  35. float width = 50;
  36. float height = 50;
  37. NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"loading_image0.png"],
  38. [UIImage imageNamed:@"loading_image1.png"],
  39. [UIImage imageNamed:@"loading_image2.png"],
  40. [UIImage imageNamed:@"loading_image3.png"],
  41. [UIImage imageNamed:@"loading_image4.png"],
  42. [UIImage imageNamed:@"loading_image5.png"],
  43. [UIImage imageNamed:@"loading_image6.png"],
  44. [UIImage imageNamed:@"loading_image7.png"],
  45. [UIImage imageNamed:@"loading_image8.png"],
  46. [UIImage imageNamed:@"loading_image9.png"],
  47. [UIImage imageNamed:@"loading_image10.png"],
  48. [UIImage imageNamed:@"loading_image11.png"],
  49. [UIImage imageNamed:@"loading_image12.png"],
  50. [UIImage imageNamed:@"loading_image13.png"],
  51. [UIImage imageNamed:@"loading_image14.png"],
  52. nil];
  53. _loadingImageView = [[UIImageView alloc] init];
  54. _loadingImageView.bounds = CGRectMake(0, 0, width, height);
  55. _loadingImageView.center = CGPointMake(CGRectGetWidth(rect) / 2, CGRectGetHeight(rect) / 2);;
  56. _loadingImageView.animationImages = array;
  57. _loadingImageView.animationDuration = 1;
  58. _loadingImageView.hidden = YES;
  59. [view addSubview:_loadingImageView];
  60. }
  61. }
  62. - (void)emptyPlayInfo
  63. {
  64. _pending = NO;
  65. _isWorking = NO;
  66. _userID = @"";
  67. _playUrl = @"";
  68. _loadingBackground = nil;
  69. _loadingImageView = nil;
  70. _reStartTimes = 0;
  71. }
  72. - (void)setLoadingText:(NSString*)text
  73. {
  74. if (_loadingTextView)
  75. {
  76. _loadingTextView.text = text;
  77. }
  78. }
  79. - (void)startLoading
  80. {
  81. if (_loadingBackground)
  82. {
  83. _loadingBackground.hidden = NO;
  84. }
  85. if (_loadingImageView)
  86. {
  87. _loadingImageView.hidden = NO;
  88. [_loadingImageView startAnimating];
  89. }
  90. }
  91. - (void)stopLoading
  92. {
  93. if (_loadingBackground)
  94. {
  95. _loadingBackground.hidden = YES;
  96. }
  97. if (_loadingImageView)
  98. {
  99. _loadingImageView.hidden = YES;
  100. [_loadingImageView stopAnimating];
  101. }
  102. }
  103. - (void)startPlay:(NSString*)playUrl
  104. {
  105. _livePlayListener.playUrl = playUrl;
  106. _playUrl = playUrl;
  107. [self reStartPlay];
  108. }
  109. - (void)reStartPlay
  110. {
  111. if (_btnKickout)
  112. {
  113. _btnKickout.hidden = YES;
  114. }
  115. if(_livePlayer)
  116. {
  117. [_livePlayer removeVideoWidget];
  118. [_livePlayer stopPlay];
  119. }
  120. if(_livePlayer)
  121. {
  122. [_livePlayer setupVideoWidget:CGRectMake(0, 0, 0, 0) containView: _videoView insertIndex:0];
  123. [_livePlayer setRenderMode:RENDER_MODE_FILL_SCREEN];
  124. [_livePlayer startLivePlay:_playUrl type:PLAY_TYPE_LIVE_RTMP_ACC];
  125. [GlobalVariables sharedInstance].isBeingLinkMic = YES;
  126. }
  127. }
  128. - (void)stopPlay
  129. {
  130. [self stopLoading];
  131. if (_btnKickout)
  132. {
  133. _btnKickout.hidden = YES;
  134. }
  135. if(_livePlayer)
  136. {
  137. [_livePlayer removeVideoWidget];
  138. [_livePlayer stopPlay];
  139. }
  140. }
  141. @end