Skip to content

Commit

Permalink
1、Solve some bugs of download
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyanzhang committed Mar 13, 2023
1 parent 57918f3 commit 82bdf51
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def common_pods_all
pod 'AFNetworking'
pod 'BlocksKit', '~> 2.2.5'
pod 'CWStatusBarNotification', '~> 2.3.5'
pod 'TXLiteAVSDK_Player', '~> 10.9.13161'
pod 'TXLiteAVSDK_Player', '~> 11.0.14028'
end

def common_pods_smart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ @interface VideoCacheListCell()

@property (nonatomic, strong) UILabel *cacheProgressLabel;

@property (nonatomic, strong) UILabel *sizeLabel;

@property (nonatomic, strong) UIView *statusView;

@property (nonatomic, strong) UILabel *statusLabel;
Expand All @@ -57,13 +59,20 @@ @implementation VideoCacheListCell
+ (void)initialize {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
gQualityDic = @ {playerLocalize(@"SuperPlayerDemo.MoviePlayer.original") : @(TXVodQualityOD),
playerLocalize(@"SuperPlayerDemo.MoviePlayer.smooth") : @(TXVodQualityFLU),
playerLocalize(@"SuperPlayerDemo.MoviePlayer.SD") : @(TXVodQualitySD),
playerLocalize(@"SuperPlayerDemo.MoviePlayer.HD") : @(TXVodQualityHD),
playerLocalize(@"SuperPlayerDemo.MoviePlayer.FHD") : @(TXVodQualityFHD),
playerLocalize(@"SuperPlayerDemo.MoviePlayer.2K") : @(TXVodQuality2K),
playerLocalize(@"SuperPlayerDemo.MoviePlayer.4K") : @(TXVodQuality4K)};
gQualityDic = @ {
@(TXVodQualityOD) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.original"),
@(TXVodQualityFLU) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.smooth"),
@(TXVodQualitySD) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.SD"),
@(TXVodQualityHD) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.HD"),
@(TXVodQualityFHD) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.FHD"),
@(TXVodQuality2K) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.2K"),
@(TXVodQuality4K) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.4K"),
@(TXVodQuality240P) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.smooth"),
@(TXVodQuality360P) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.smooth"),
@(TXVodQuality480P) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.SD"),
@(TXVodQuality540P) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.SD"),
@(TXVodQuality720P) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.HD"),
@(TXVodQuality1080p) : playerLocalize(@"SuperPlayerDemo.MoviePlayer.HD")};
});
}

Expand Down Expand Up @@ -96,12 +105,18 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr
make.width.mas_equalTo(140);
}];

[self addSubview:self.sizeLabel];
[self.sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(20 + 114 + 10);
make.top.equalTo(self).offset(10 + 16 + 24 + 4);
make.height.mas_equalTo(16);
}];

[self addSubview:self.cacheProgressLabel];
[self.cacheProgressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(20 + 114 + 10);
make.left.equalTo(self.sizeLabel.mas_right).offset(5);
make.top.equalTo(self).offset(10 + 16 + 24 + 4);
make.height.mas_equalTo(16);
make.width.mas_equalTo(120);
}];

[self addSubview:self.resolutionLabel];
Expand Down Expand Up @@ -145,7 +160,8 @@ - (void)setModel:(VideoCacheListModel *)model {
[self updateQuality:dataSource.quality];
[self updateProgress:self.mediaInfo.progress];
[self updateCacheState:self.mediaInfo.downloadState];

CGFloat size = model.mediaInfo.size * 1.0f / 1024 / 1024;
self.sizeLabel.text = [NSString stringWithFormat:@"%0.2fM",size];
NSString *key = nil;
if (dataSource.appId != 0 && dataSource.fileId.length != 0) {
key = [NSString stringWithFormat:@"%d%@%ld",dataSource.appId,dataSource.fileId,(long)dataSource.quality];
Expand Down Expand Up @@ -233,11 +249,14 @@ - (void)stopDownload {

- (SuperPlayerModel *)getSuperPlayModel {
SuperPlayerModel *playModel = [[SuperPlayerModel alloc] init];
if (self.mediaInfo.playPath.length > 0 && self.mediaInfo.downloadState == TXVodDownloadMediaInfoStateFinish) {



if (self.mediaInfo.playPath.length > 0 && self.mediaInfo.downloadState == 4) {
SuperPlayerUrl *playerUrl = [[SuperPlayerUrl alloc] init];
[gQualityDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
if ([obj integerValue] == self.mediaInfo.dataSource.quality) {
playerUrl.title = key;
if ([key integerValue] == self.mediaInfo.dataSource.quality) {
playerUrl.title = obj;
*stop = YES;
}
}];
Expand Down Expand Up @@ -275,8 +294,8 @@ - (SuperPlayerModel *)getSuperPlayModel {
- (void)updateQuality:(NSInteger)quality {
__weak __typeof(self) weakSelf = self;
[gQualityDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
if ([obj integerValue] == quality) {
weakSelf.resolutionLabel.text = key;
if ([key integerValue] == quality) {
weakSelf.resolutionLabel.text = obj;
*stop = YES;
}
}];
Expand Down Expand Up @@ -465,10 +484,24 @@ - (UILabel *)cacheProgressLabel {
_cacheProgressLabel.font = [UIFont systemFontOfSize:12];
_cacheProgressLabel.textColor = [UIColor grayColor];
_cacheProgressLabel.textAlignment = NSTextAlignmentLeft;
[_cacheProgressLabel setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
}
return _cacheProgressLabel;
}

- (UILabel *)sizeLabel {
if (!_sizeLabel) {
_sizeLabel = [[UILabel alloc] init];
_sizeLabel.font = [UIFont systemFontOfSize:12];
_sizeLabel.textColor = [UIColor grayColor];
_sizeLabel.textAlignment = NSTextAlignmentLeft;
[_sizeLabel setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
}
return _sizeLabel;
}

- (UILabel *)resolutionLabel {
if (!_resolutionLabel) {
_resolutionLabel = [[UILabel alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,22 @@ - (TXVodDownloadMediaInfo *)getDownloadMediaInfo:(SuperPlayerModel *)model {
}

- (int)getCurrentQuality {
__block int quality;
__block int quality = TXVodQuality720P;
__block NSString *title;
[self.currentModel.multiVideoURLs enumerateObjectsUsingBlock:^(SuperPlayerUrl * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.title containsString:self.currentResolutionStr]) {
quality = obj.qualityIndex;
title = obj.title;
*stop = YES;
}
}];

//根据分辨率指定清晰度
NSArray *titlesArray = [title componentsSeparatedByString:@""];
NSArray *resoluArray = [titlesArray.lastObject componentsSeparatedByString:@"P)"];
NSString *resolution = resoluArray.firstObject;
if(resolution.length > 0){
quality = [resolution intValue];
}
return quality;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ - (void)_refreshVODList {
[videoArray addObject:p];
[_authParamArray addObject:videoArray];

videoArray = [NSMutableArray array];
p = [[TXPlayerAuthParams alloc] init];
p.appId = 1500005830;
p.fileId = @"243791578431393746";
[videoArray addObject:p];
[_authParamArray addObject:videoArray];

videoArray = [NSMutableArray array];
TXMoviePlayInfoResponse *trackInfoResponse = [[TXMoviePlayInfoResponse alloc] init];
trackInfoResponse.name = playerLocalize(@"SuperPlayerDemo.MoviePlayer.multitrackvideo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
NSString *superPlayerLocalizeFromTable(NSString *key, NSString *table) {
NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
if ([languages count] <= 0) { // 语言包判断
return key;
languages = [NSArray arrayWithObject:@"en"];
}

NSString *preferredLang = [languages objectAtIndex:0]; // zh-Hant-GB
Expand All @@ -24,7 +24,8 @@
NSString *bundleOfPath = [NSBundle pathForResource:languageProj ofType:@"lproj" inDirectory:resourceDict];
NSBundle *bundle = [NSBundle bundleWithPath:bundleOfPath];
if (!bundle) { // 语言lproj的判断
return key;
bundleOfPath = [NSBundle pathForResource:@"en" ofType:@"lproj" inDirectory:resourceDict];
bundle = [NSBundle bundleWithPath:bundleOfPath];
}

return [bundle localizedStringForKey:key value:@"" table:table];
Expand Down

0 comments on commit 82bdf51

Please sign in to comment.