Commit 99a8b6b24cd2820b409d2ca65df55b7f42d3c225

Authored by yanglingyu
1 parent 4de6d3e9

直播流及时更新

CNLiveScioLive/Pages/Live/Controller/CNLiveViewController.m
... ... @@ -59,7 +59,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
59 59 NSData *data = [dic mj_JSONData];
60 60 [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"LiveHeader"];
61 61 [self dealDictionaryData:data];
62   -// self->_isLoaded = YES;
63 62  
64 63 } failure:^(NSError *error) {
65 64 [MBProgressHUD hideHUDForView:self.view animated:YES];
... ... @@ -202,9 +201,7 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
202 201 _isRefreshing = YES;
203 202 [self loadYGData];
204 203 [self loadData];
205   - if(!_isLoaded){
206   - [self getData];
207   - }
  204 + [self getData];
208 205 }
209 206 }
210 207 - (void)loadMoreData{
... ... @@ -212,8 +209,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
212 209 _isRefreshing = YES;
213 210 [self loadData];
214 211 }
215   -// [self.tableView.mj_footer endRefreshing];
216   -// [AlertViewTool showHUDViewText:@"查看往期发布会回放,请点击搜索按钮" block:nil duration:1.5];
217 212  
218 213 }
219 214 - (void)viewWillAppear:(BOOL)animated{
... ... @@ -239,7 +234,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
239 234  
240 235 _pageNo = 1;
241 236 _isRefreshing = NO;
242   - _isLoaded = NO;
243 237 [self loadData];
244 238 [self loadYGData];
245 239 [self.view addSubview:self.tableView];
... ... @@ -255,6 +249,9 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
255 249 GraphicLiveViewController *vc = [[GraphicLiveViewController alloc] initWithDictionary:dic];
256 250 vc.relatedArray = [NSArray arrayWithArray:blockSelf->_newsArray];
257 251 vc.hidesBottomBarWhenPushed = YES;
  252 + vc.reloadData = ^{
  253 + [weakSelf loadUpData];
  254 + };
258 255 [weakSelf.navigationController pushViewController:vc animated:YES];
259 256 return;
260 257 };
... ... @@ -423,6 +420,10 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
423 420 GraphicLiveViewController *vc = [[GraphicLiveViewController alloc] initWithDictionary:dic];
424 421 vc.relatedArray = [NSArray arrayWithArray:_newsArray];
425 422 vc.hidesBottomBarWhenPushed = YES;
  423 + MJWeakSelf
  424 + vc.reloadData = ^{
  425 + [weakSelf loadUpData];
  426 + };
426 427 [self.navigationController pushViewController:vc animated:YES];
427 428 return;
428 429  
... ...
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.h
... ... @@ -18,6 +18,7 @@ typedef NS_ENUM(NSInteger, PlayerType) {
18 18 PlayerTypeNormal // 普通URL模式
19 19 };
20 20  
  21 +typedef void(^DataChanged)(void);
21 22 @interface GraphicLiveViewController : CNLiveBaseViewController<WKNavigationDelegate>{
22 23 UIScrollView *backgroundView;
23 24 UIImageView *imageView;
... ... @@ -54,6 +55,7 @@ typedef NS_ENUM(NSInteger, PlayerType) {
54 55 @property (nonatomic, assign) PlayerType type;
55 56  
56 57 @property (nonatomic, strong) NSArray *relatedArray;
  58 +@property (nonatomic, copy) DataChanged reloadData;
57 59  
58 60 - (id)initWithDictionary:(NSDictionary*)dictionary;
59 61  
... ...
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.m
... ... @@ -8,6 +8,7 @@
8 8 #import "JSONKit.h"
9 9 #import "GraphicLiveViewController.h"
10 10 #import "VideoPlayBackViewController.h"
  11 +#import "CNLiveModel.h"
11 12  
12 13 @interface GraphicLiveViewController ()<CNLivePlayerControllerDelegate>
13 14 @end
... ... @@ -16,32 +17,72 @@
16 17 [self.videoController stop];
17 18 [self.navigationController popViewControllerAnimated:YES];
18 19 }
  20 +- (void)getData{
  21 + [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  22 + [XWHTTPTool POST:LiveUrl params:nil success:^(id json) {
19 23  
  24 + [MBProgressHUD hideHUDForView:self.view animated:YES];
  25 +
  26 + // 请求成功,解析数据
  27 + NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json];
  28 + [CNLiveModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
  29 + return @{ @"ID" : @"id" ,@"Description" : @"description" };
  30 + }];
  31 + CNLiveModel *liveModel = [CNLiveModel mj_objectWithKeyValues:dic];
  32 + if (![self->_dictionary isEqualToDictionary:[liveModel toDictionary] ]) {
  33 + self->_dictionary = [liveModel toDictionary];
  34 + self.reloadData();
  35 + [self updateUIData];
  36 + }else{
  37 + [self updateUIData];
  38 + }
  39 +
  40 +// self->_isLoaded = YES;
  41 +
  42 + } failure:^(NSError *error) {
  43 + [MBProgressHUD hideHUDForView:self.view animated:YES];
  44 + [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")];
  45 + [self updateUIData];
  46 + }];
  47 +}
  48 +
  49 +-(void)updateUIData{
  50 + int status = [_dictionary[@"status"] intValue];
  51 + int liveFlag = [_dictionary[@"liveFlag"] intValue];
  52 + if (4 == status) {
  53 + if (_dictionary[@"playbackId"]) {
  54 + // 回放
  55 + isPlay = YES;
  56 + self.type = PlayerTypeVOD;
  57 + } else {
  58 + isPlay = NO;
  59 + }
  60 + } else if (1 == status) {
  61 + // 直播
  62 + url = _dictionary[@"liveUrl"];
  63 + if (0 == liveFlag) {
  64 + isPlay = YES;
  65 + self.type = PlayerTypeLiving;
  66 + } else {
  67 + isPlay = NO;
  68 + self.type = -1;
  69 + }
  70 + }
  71 + NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<html><font style=\"font-size:20px;\"><strong>%@</strong></font><br><p>%@</p><p>%@:%@</p><body>",[_dictionary objectForKey:@"title"],[_dictionary objectForKey:@"liveStartDateTime"], CustomStr(@"Source"), @"国新网"];
  72 + NSString* htmlFooter = [[NSString alloc] initWithFormat:@"<div class=\"logo\" style=\"text-indent:2em\">%@</div></body></html>",[_dictionary objectForKey:@"Description"]];
  73 +
  74 + NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@",htmlHeader,htmlFooter];
  75 + [relatedWebView loadHTMLString:strHtml baseURL:nil];
  76 + if (!isPlay) {
  77 + [self loadMovieView];
  78 + } else {
  79 + [self addCNLivePlayerWithURL];
  80 + }
  81 +}
20 82 - (id)initWithDictionary:(NSDictionary *)dictionary {
21 83 if (self = [super init]) {
22 84 _dictionary = [NSDictionary dictionaryWithDictionary:dictionary];
23   - int status = [_dictionary[@"status"] intValue];
24   - int liveFlag = [_dictionary[@"liveFlag"] intValue];
25   - if (4 == status) {
26   - if (_dictionary[@"playbackId"]) {
27   - // 回放
28   - isPlay = YES;
29   - self.type = PlayerTypeVOD;
30   - } else {
31   - isPlay = NO;
32   - }
33   - } else if (1 == status) {
34   - // 直播
35   - url = _dictionary[@"liveUrl"];
36   - if (0 == liveFlag) {
37   - isPlay = YES;
38   - self.type = PlayerTypeLiving;
39   - } else {
40   - isPlay = NO;
41   - self.type = -1;
42   - }
43   - }
44   - videoHeight = MainScreenWidth * (9.0 / 16.0);
  85 + [self getData];
45 86 }
46 87 return self;
47 88 }
... ... @@ -130,7 +171,7 @@
130 171 fontIndex = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
131 172 heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]];
132 173 fontArray = @[@"16",@"20",@"24"];
133   -
  174 + videoHeight = MainScreenWidth * (9.0 / 16.0);
134 175 if (iPhoneX) {
135 176 backgroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, videoHeight + 44, MainScreenWidth, MainScreenHeight - videoHeight - 44)];
136 177 } else {
... ... @@ -158,17 +199,6 @@
158 199 relatedWebView.tag = 1000;
159 200 [backgroundView addSubview:relatedWebView];
160 201  
161   - NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<html><font style=\"font-size:20px;\"><strong>%@</strong></font><br><p>%@</p><p>%@:%@</p><body>",[_dictionary objectForKey:@"title"],[_dictionary objectForKey:@"liveStartDateTime"], CustomStr(@"Source"), @"国新网"];
162   - NSString* htmlFooter = [[NSString alloc] initWithFormat:@"<div class=\"logo\" style=\"text-indent:2em\">%@</div></body></html>",[_dictionary objectForKey:@"Description"]];
163   -
164   - NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@",htmlHeader,htmlFooter];
165   - [relatedWebView loadHTMLString:strHtml baseURL:nil];
166   -
167   - if (!isPlay) {
168   - [self loadMovieView];
169   - } else {
170   - [self addCNLivePlayerWithURL];
171   - }
172 202  
173 203 [self loadData];
174 204 isShow = NO;
... ...