Commit 99a8b6b24cd2820b409d2ca65df55b7f42d3c225

Authored by yanglingyu
1 parent 4de6d3e9

直播流及时更新

CNLiveScioLive/Pages/Live/Controller/CNLiveViewController.m
@@ -59,7 +59,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; @@ -59,7 +59,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
59 NSData *data = [dic mj_JSONData]; 59 NSData *data = [dic mj_JSONData];
60 [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"LiveHeader"]; 60 [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"LiveHeader"];
61 [self dealDictionaryData:data]; 61 [self dealDictionaryData:data];
62 -// self->_isLoaded = YES;  
63 62
64 } failure:^(NSError *error) { 63 } failure:^(NSError *error) {
65 [MBProgressHUD hideHUDForView:self.view animated:YES]; 64 [MBProgressHUD hideHUDForView:self.view animated:YES];
@@ -202,9 +201,7 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; @@ -202,9 +201,7 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
202 _isRefreshing = YES; 201 _isRefreshing = YES;
203 [self loadYGData]; 202 [self loadYGData];
204 [self loadData]; 203 [self loadData];
205 - if(!_isLoaded){  
206 - [self getData];  
207 - } 204 + [self getData];
208 } 205 }
209 } 206 }
210 - (void)loadMoreData{ 207 - (void)loadMoreData{
@@ -212,8 +209,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; @@ -212,8 +209,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
212 _isRefreshing = YES; 209 _isRefreshing = YES;
213 [self loadData]; 210 [self loadData];
214 } 211 }
215 -// [self.tableView.mj_footer endRefreshing];  
216 -// [AlertViewTool showHUDViewText:@"查看往期发布会回放,请点击搜索按钮" block:nil duration:1.5];  
217 212
218 } 213 }
219 - (void)viewWillAppear:(BOOL)animated{ 214 - (void)viewWillAppear:(BOOL)animated{
@@ -239,7 +234,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; @@ -239,7 +234,6 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
239 234
240 _pageNo = 1; 235 _pageNo = 1;
241 _isRefreshing = NO; 236 _isRefreshing = NO;
242 - _isLoaded = NO;  
243 [self loadData]; 237 [self loadData];
244 [self loadYGData]; 238 [self loadYGData];
245 [self.view addSubview:self.tableView]; 239 [self.view addSubview:self.tableView];
@@ -255,6 +249,9 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; @@ -255,6 +249,9 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
255 GraphicLiveViewController *vc = [[GraphicLiveViewController alloc] initWithDictionary:dic]; 249 GraphicLiveViewController *vc = [[GraphicLiveViewController alloc] initWithDictionary:dic];
256 vc.relatedArray = [NSArray arrayWithArray:blockSelf->_newsArray]; 250 vc.relatedArray = [NSArray arrayWithArray:blockSelf->_newsArray];
257 vc.hidesBottomBarWhenPushed = YES; 251 vc.hidesBottomBarWhenPushed = YES;
  252 + vc.reloadData = ^{
  253 + [weakSelf loadUpData];
  254 + };
258 [weakSelf.navigationController pushViewController:vc animated:YES]; 255 [weakSelf.navigationController pushViewController:vc animated:YES];
259 return; 256 return;
260 }; 257 };
@@ -423,6 +420,10 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell"; @@ -423,6 +420,10 @@ static NSString *indicatorTableViewCell = @"CNLiveIndicatorTableViewCell";
423 GraphicLiveViewController *vc = [[GraphicLiveViewController alloc] initWithDictionary:dic]; 420 GraphicLiveViewController *vc = [[GraphicLiveViewController alloc] initWithDictionary:dic];
424 vc.relatedArray = [NSArray arrayWithArray:_newsArray]; 421 vc.relatedArray = [NSArray arrayWithArray:_newsArray];
425 vc.hidesBottomBarWhenPushed = YES; 422 vc.hidesBottomBarWhenPushed = YES;
  423 + MJWeakSelf
  424 + vc.reloadData = ^{
  425 + [weakSelf loadUpData];
  426 + };
426 [self.navigationController pushViewController:vc animated:YES]; 427 [self.navigationController pushViewController:vc animated:YES];
427 return; 428 return;
428 429
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.h
@@ -18,6 +18,7 @@ typedef NS_ENUM(NSInteger, PlayerType) { @@ -18,6 +18,7 @@ typedef NS_ENUM(NSInteger, PlayerType) {
18 PlayerTypeNormal // 普通URL模式 18 PlayerTypeNormal // 普通URL模式
19 }; 19 };
20 20
  21 +typedef void(^DataChanged)(void);
21 @interface GraphicLiveViewController : CNLiveBaseViewController<WKNavigationDelegate>{ 22 @interface GraphicLiveViewController : CNLiveBaseViewController<WKNavigationDelegate>{
22 UIScrollView *backgroundView; 23 UIScrollView *backgroundView;
23 UIImageView *imageView; 24 UIImageView *imageView;
@@ -54,6 +55,7 @@ typedef NS_ENUM(NSInteger, PlayerType) { @@ -54,6 +55,7 @@ typedef NS_ENUM(NSInteger, PlayerType) {
54 @property (nonatomic, assign) PlayerType type; 55 @property (nonatomic, assign) PlayerType type;
55 56
56 @property (nonatomic, strong) NSArray *relatedArray; 57 @property (nonatomic, strong) NSArray *relatedArray;
  58 +@property (nonatomic, copy) DataChanged reloadData;
57 59
58 - (id)initWithDictionary:(NSDictionary*)dictionary; 60 - (id)initWithDictionary:(NSDictionary*)dictionary;
59 61
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.m
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 #import "JSONKit.h" 8 #import "JSONKit.h"
9 #import "GraphicLiveViewController.h" 9 #import "GraphicLiveViewController.h"
10 #import "VideoPlayBackViewController.h" 10 #import "VideoPlayBackViewController.h"
  11 +#import "CNLiveModel.h"
11 12
12 @interface GraphicLiveViewController ()<CNLivePlayerControllerDelegate> 13 @interface GraphicLiveViewController ()<CNLivePlayerControllerDelegate>
13 @end 14 @end
@@ -16,32 +17,72 @@ @@ -16,32 +17,72 @@
16 [self.videoController stop]; 17 [self.videoController stop];
17 [self.navigationController popViewControllerAnimated:YES]; 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 - (id)initWithDictionary:(NSDictionary *)dictionary { 82 - (id)initWithDictionary:(NSDictionary *)dictionary {
21 if (self = [super init]) { 83 if (self = [super init]) {
22 _dictionary = [NSDictionary dictionaryWithDictionary:dictionary]; 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 return self; 87 return self;
47 } 88 }
@@ -130,7 +171,7 @@ @@ -130,7 +171,7 @@
130 fontIndex = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"]; 171 fontIndex = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
131 heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]]; 172 heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]];
132 fontArray = @[@"16",@"20",@"24"]; 173 fontArray = @[@"16",@"20",@"24"];
133 - 174 + videoHeight = MainScreenWidth * (9.0 / 16.0);
134 if (iPhoneX) { 175 if (iPhoneX) {
135 backgroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, videoHeight + 44, MainScreenWidth, MainScreenHeight - videoHeight - 44)]; 176 backgroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, videoHeight + 44, MainScreenWidth, MainScreenHeight - videoHeight - 44)];
136 } else { 177 } else {
@@ -158,17 +199,6 @@ @@ -158,17 +199,6 @@
158 relatedWebView.tag = 1000; 199 relatedWebView.tag = 1000;
159 [backgroundView addSubview:relatedWebView]; 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 [self loadData]; 203 [self loadData];
174 isShow = NO; 204 isShow = NO;