Skip to content

Commit

Permalink
修复UI状态相关bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchao0033 committed Apr 9, 2016
1 parent c88fef7 commit 71265e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
41 changes: 26 additions & 15 deletions HLS-Test/Classes/YCHLSDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ - (void)viewDidLoad {
self.downloadButton.enabled = NO;
self.clearButton.enabled = YES;
self.progressView.progress = 1;
self.progressLabel.text = @"100%";
/** 配置MSU8解析器 */
M3U8Handler *handler = [[M3U8Handler alloc] init];
[handler praseUrl:[NSString stringWithFormat:@"%@", self.URLString]];
Expand All @@ -76,13 +77,17 @@ - (void)viewDidLoad {
[self.downloader removeObserver:self forKeyPath:@"currentProgress"];
self.downloader = nil;
}
/** 初始化下载对象 */
self.downloader = [[VideoDownloader alloc] initWithM3U8List:handler.playlist];
[self.downloader addObserver:self forKeyPath:@"clearCaches" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; // 判断是否清理缓存
[self.downloader addObserver:self forKeyPath:@"currentProgress" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
/** 初始化下载对象 */
self.downloader = [[VideoDownloader alloc] initWithM3U8List:handler.playlist];
[self.downloader addObserver:self forKeyPath:@"clearCaches" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; // 判断是否清理缓存
[self.downloader addObserver:self forKeyPath:@"currentProgress" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.downloader cancelDownloadVideo];
}
- (void)openHttpServer
{
self.httpServer = [[HTTPServer alloc] init];
Expand Down Expand Up @@ -124,6 +129,10 @@ - (IBAction)playLiveStreaming {
#pragma mark - 视频下载
- (IBAction)downloadStreamingMedia:(id)sender {


[self.downloadButton setTitle:@"下载中" forState:UIControlStateNormal];
self.downloadButton.enabled = NO;

UIButton *downloadButton = sender;
// 获取本地Library/Cache路径
NSString *localDownloadsPath = [kLibraryCache stringByAppendingPathComponent:kPathDownload];
Expand Down Expand Up @@ -166,16 +175,14 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS
{
if ([keyPath isEqualToString:@"clearCaches"]) {
NSLog(@"%@", change);
// if (change[@"new"]) {
self.downloadButton.enabled = YES;
[self.downloadButton setTitle:@"下载" forState:UIControlStateNormal];
self.clearButton.enabled = NO;
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:@"isDownload"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.progressView.progress = 0.0;
self.progressLabel.text = [NSString stringWithFormat:@"%.2f%%", 0.0];
// }

self.downloadButton.enabled = YES;
[self.downloadButton setTitle:@"下载" forState:UIControlStateNormal];
self.downloadButton.enabled = YES;
self.clearButton.enabled = NO;
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:@"isDownload"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.progressView.progress = 0.0;
self.progressLabel.text = [NSString stringWithFormat:@"%.2f%%", 0.0];
}else{
self.progressLabel.text = [NSString stringWithFormat:@"%.2f%%", 100 * [[change objectForKey:@"new"] floatValue]];
self.progressView.progress = [[change objectForKey:@"new"] floatValue];
Expand All @@ -185,6 +192,9 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS
[[NSUserDefaults standardUserDefaults] synchronize];
self.clearButton.enabled = YES;
self.downloadButton.enabled = NO;
} else {
// [self.downloadButton setTitle:@"下载中" forState:UIControlStateNormal];
// self.downloadButton.enabled = NO;
}
}

Expand Down Expand Up @@ -223,7 +233,8 @@ -(void)videoDownloaderFinished:(VideoDownloader*)request
-(void)videoDownloaderFailed:(VideoDownloader*)request

{

[self.downloadButton setTitle:@"下载" forState:UIControlStateNormal];
self.downloadButton.enabled = YES;
NSLog(@"----------视频下载失败-----------");

}
Expand Down
2 changes: 1 addition & 1 deletion HLS-Test/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
alertView.tag = 900;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textFiled = [alertView textFieldAtIndex:0];
textFiled.text = @"http://devstreaming.apple.com/videos/wwdc/2015/413eflf3lrh1tyo/413/0640/0640.m3u8";
textFiled.text = @"http://pl.youku.com/playlist/m3u8?ts=1460190028&keyframe=0&pid=6b5f94f4ab33c702&vid=XNzgxMTQyMzIw&type=hd2&r=/3sLngL0Q6CXymAIiF9JUQQtnOFNJPUClO8A56KJJcT8UB+NRAMQ09zE6rNj4EKMxAvRByWf6hitgv75Fv0ffeukHu0/cHPmEJbqRoQB5wVU/l3ZcBOSsxUf7QaPO6gDptAU4mTDRr+dVJThYEJUnhDylfynOikSdSxEqBFdeDY7+0iOLRI4iPtRlKx5jngj&ypremium=1&oip=1992409311&token=5701&sid=74601900286162054962a&did=1460189987&ev=1&ctype=20&ep=0nFhXc%2B6QqgNpi46UejQ2JQw5hPsb0UdjjMSGiBdsIV9nwiIZRIiNvonOZh89iYe";
textFiled.clearButtonMode = UITextFieldViewModeAlways;
[alertView show];

Expand Down

0 comments on commit 71265e9

Please sign in to comment.