Skip to content

Commit

Permalink
1、Update Demo for new function
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyanzhang committed Jan 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7c0c1d1 commit 907042f
Showing 10 changed files with 116 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Demo/Podfile
Original file line number Diff line number Diff line change
@@ -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.13148'
pod 'TXLiteAVSDK_Player', '~> 10.9.13161'
end

def common_pods_smart
Original file line number Diff line number Diff line change
@@ -260,46 +260,55 @@ - (NSMutableArray *)loadDashVideo {
FeedVideoModel *model1 = [FeedVideoModel new];
model1.videoURL = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.20.mpd";
model1.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.asingle.morebitrate");
model1.duration = 90;
[result addObject:model1];

FeedVideoModel *model2 = [FeedVideoModel new];
model2.videoURL = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.22.mpd";
model2.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.asingle.morebitrate");
model2.duration = 90;
[result addObject:model2];

FeedVideoModel *model3 = [FeedVideoModel new];
model3.videoURL = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.1163819.mpd";
model3.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.asingle.morebitrate");
model3.duration = 90;
[result addObject:model3];

FeedVideoModel *model4 = [FeedVideoModel new];
model4.videoURL = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.1163820.mpd";
model4.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.asingle.morebitrate");
model4.duration = 90;
[result addObject:model4];

FeedVideoModel *model5 = [FeedVideoModel new];
model5.videoURL = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.9101.mpd";
model5.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.DRMwidevine");
model5.duration = 90;
[result addObject:model5];

FeedVideoModel *model6 = [FeedVideoModel new];
model6.videoURL = @"https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd";
model6.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.numberbased");
model6.duration = 210;
[result addObject:model6];

FeedVideoModel *model7 = [FeedVideoModel new];
model7.videoURL = @"https://dash.akamaized.net/dash264/TestCases/2c/qualcomm/1/MultiResMPEG2.mpd";
model7.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.timebased");
model7.duration = 654;
[result addObject:model7];

FeedVideoModel *model8 = [FeedVideoModel new];
model8.videoURL = @"https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
model8.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.30fps");
model8.duration = 634;
[result addObject:model8];

FeedVideoModel *model9 = [FeedVideoModel new];
model9.videoURL = @"https://dash.akamaized.net/akamai/test/caption_test/ElephantsDream/elephants_dream_480p_heaac5_1_https.mpd";
model9.title = playerLocalize(@"SuperPlayerDemo.VideoFeeds.dash.withsubtitle");
model9.duration = 653;
[result addObject:model9];

return result;
4 changes: 2 additions & 2 deletions Demo/TXLiteAVDemo/SuperPlayFeedDemo/Views/FeedDetailView.m
Original file line number Diff line number Diff line change
@@ -120,9 +120,9 @@ - (SuperPlayerModel *)setSuperPlayerModel:(FeedDetailModel *)model {

playerModel.appId = model.appId;
videoId.fileId = model.fileId;
videoId.psign = nil;
videoId.psign = [model valueForKey:@"pSign"];
playerModel.videoId = videoId;
playerModel.videoURL = nil;
playerModel.videoURL = [model valueForKey:@"videoURL"];
playerModel.action = PLAY_ACTION_AUTO_PLAY;
playerModel.defaultCoverImageUrl = model.coverUrl;

Original file line number Diff line number Diff line change
@@ -134,7 +134,9 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr
}

- (void)setModel:(VideoCacheListModel *)model {

_model = model;

self.mediaInfo = model.mediaInfo;

[self.manager registerListener:self.callback info:self.mediaInfo];
@@ -144,13 +146,28 @@ - (void)setModel:(VideoCacheListModel *)model {
[self updateProgress:self.mediaInfo.progress];
[self updateCacheState:self.mediaInfo.downloadState];

NSString *key = [NSString stringWithFormat:@"%d%@%ld",dataSource.appId,dataSource.fileId,(long)dataSource.quality];
NSString *key = nil;
if (dataSource.appId != 0 && dataSource.fileId.length != 0) {
key = [NSString stringWithFormat:@"%d%@%ld",dataSource.appId,dataSource.fileId,(long)dataSource.quality];
}

NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:key];
if (dic.count > 0) {
model.videoName = [dic objectForKey:@"videoName"];
model.coverImageStr = [dic objectForKey:@"coverImage"];
model.durationStr = [dic objectForKey:@"duration"];

dispatch_async(dispatch_get_main_queue(), ^{
if (model.coverImageStr.length > 0) {
[self.videoImageView sd_setImageWithURL:[NSURL URLWithString:model.coverImageStr] placeholderImage:[UIImage imageNamed:@"img_video_loading"]];
}
self.durationLabel.text = model.durationStr;
self.videoNameLabel.text = model.videoName;
});
} else {
NSInteger duration = model.mediaInfo.duration;
NSString *durationStr = [NSString stringWithFormat:@"%02ld:%02ld", duration /60, duration % 60];
model.durationStr = durationStr;
dispatch_async(dispatch_get_main_queue(), ^{
if (model.coverImageStr.length > 0) {
[self.videoImageView sd_setImageWithURL:[NSURL URLWithString:model.coverImageStr] placeholderImage:[UIImage imageNamed:@"img_video_loading"]];
@@ -161,33 +178,35 @@ - (void)setModel:(VideoCacheListModel *)model {
}

__weak typeof(self) weakSelf = self;
[self getPlayInfo:dataSource.appId fileId:dataSource.fileId psign:dataSource.pSign completion:^(NSMutableDictionary *dic, NSError *error) {
if (error) {
NSLog(@"%@",error.userInfo);
} else {
NSString *name = [dic objectForKey:@"videoDescription"];
NSString *videoName = name.length > 0 ? name : [dic objectForKey:@"name"];
NSString *coverImage = [dic objectForKey:@"coverUrl"];
NSInteger duration = [[dic objectForKey:@"duration"] integerValue];
NSString *durationStr = [NSString stringWithFormat:@"%02ld:%02ld", duration /60, duration % 60];
weakSelf.model.videoName = videoName;
weakSelf.model.coverImageStr = coverImage;
weakSelf.model.durationStr = durationStr;

NSDictionary *dic = @{@"videoName" : videoName, @"coverImage" : coverImage, @"duration" : durationStr};
NSString *keyStr = [NSString stringWithFormat:@"%d%@%ld",dataSource.appId,dataSource.fileId,(long)dataSource.quality];
[[NSUserDefaults standardUserDefaults] setObject:dic forKey:keyStr];
[[NSUserDefaults standardUserDefaults] synchronize];

dispatch_async(dispatch_get_main_queue(), ^{
if (coverImage.length > 0) {
[weakSelf.videoImageView sd_setImageWithURL:[NSURL URLWithString:coverImage] placeholderImage:[UIImage imageNamed:@"img_video_loading"]];
}
weakSelf.durationLabel.text = durationStr;
weakSelf.videoNameLabel.text = videoName;
});
}
}];
if (dataSource.appId != 0 && dataSource.fileId.length != 0) { // 增加参数判断,减少非必要的请求
[self getPlayInfo:dataSource.appId fileId:dataSource.fileId psign:dataSource.pSign completion:^(NSMutableDictionary *dic, NSError *error) {
if (error) {
NSLog(@"%@",error.userInfo);
} else {
NSString *name = [dic objectForKey:@"videoDescription"];
NSString *videoName = name.length > 0 ? name : [dic objectForKey:@"name"];
NSString *coverImage = [dic objectForKey:@"coverUrl"];
NSInteger duration = [[dic objectForKey:@"duration"] integerValue];
NSString *durationStr = [NSString stringWithFormat:@"%02ld:%02ld", duration /60, duration % 60];
weakSelf.model.videoName = videoName;
weakSelf.model.coverImageStr = coverImage;
weakSelf.model.durationStr = durationStr;

NSDictionary *dic = @{@"videoName" : videoName, @"coverImage" : coverImage, @"duration" : durationStr};
NSString *keyStr = [NSString stringWithFormat:@"%d%@%ld",dataSource.appId,dataSource.fileId,(long)dataSource.quality];
[[NSUserDefaults standardUserDefaults] setObject:dic forKey:keyStr];
[[NSUserDefaults standardUserDefaults] synchronize];

dispatch_async(dispatch_get_main_queue(), ^{
if (coverImage.length > 0) {
[weakSelf.videoImageView sd_setImageWithURL:[NSURL URLWithString:coverImage] placeholderImage:[UIImage imageNamed:@"img_video_loading"]];
}
weakSelf.durationLabel.text = durationStr;
weakSelf.videoNameLabel.text = videoName;
});
}
}];
}

TXVodDownloadMediaInfo *info = [[TXVodDownloadManager shareInstance] getDownloadMediaInfo:self.mediaInfo];
[self updateQuality:info.dataSource.quality];
@@ -198,7 +217,12 @@ - (void)setModel:(VideoCacheListModel *)model {
- (void)startDownload {
[self updateCacheState:1];
_model.mediaInfo.downloadState = 1;
[self.manager startDownload:self.mediaInfo];
id drmbuilder = [self.mediaInfo valueForKey:@"drmBuilder"];
if (drmbuilder) {
[self.manager startDownloadWithDRMBuilder:drmbuilder];
} else {
[self.manager startDownload:self.mediaInfo];
}
}

- (void)stopDownload {
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
// Copyright © 2022年 Tencent. All rights reserved.

#import <Foundation/Foundation.h>
#import "TXPlayerDrmBuilder.h"

NS_ASSUME_NONNULL_BEGIN

@@ -25,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, strong) NSString *url;

@property (nonatomic, strong) TXPlayerDrmBuilder *drmBuilder;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -248,6 +248,26 @@ - (void)updateVideoModel {
[self.videoArray addObject:cacheModel];
}

// cacheModel1
VideoCacheModel *cacheModel1 = [[VideoCacheModel alloc] init];
TXPlayerDrmBuilder *drmBuilder1 = [[TXPlayerDrmBuilder alloc] init];
drmBuilder1.deviceCertificateUrl = @"https://cert.drm.vod-qcloud.com/cert/v1/59ca267fdd87903b933cb845b844eda2/fairplay.cer";
drmBuilder1.keyLicenseUrl = @"https://fairplay-test.drm.vod-qcloud.com/fairplay/getlicense/v2?drmToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIjoiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxMzc4OCwiZmlsZUlkIjoiNTI4Nzg1MjEwOTg0ODE0NzI1MSIsImN1cnJlbnRUaW1lU3RhbXAiOjAsImV4cGlyZVRpbWVTdGFtcCI6MTk2MDk5NTE3MCwicmFuZG9tIjowLCJvdmVybGF5S2V5IjoiIiwib3ZlcmxheUl2IjoiIiwiY2lwaGVyZWRPdmVybGF5S2V5IjoiIiwiY2lwaGVyZWRPdmVybGF5SXYiOiIiLCJrZXlJZCI6MCwic3RyaWN0TW9kZSI6MCwicGVyc2lzdGVudCI6Ik9OIiwicmVudGFsRHVyYXRpb24iOjEwMDAwMH0~wbXINOOUyEoi3Qh5hIaISbD9gcv9QHGn89mjjHVcHPo";
drmBuilder1.playUrl = @"https://1500013788.vod2.myqcloud.com/43953aebvodtranscq1500013788/986b43ec5287852109848147251/adp.153829.m3u8";
cacheModel1.drmBuilder = drmBuilder1;
cacheModel1.videoTitle = @"FairPlay HLS(license 长期有效)";
[self.videoArray addObject:cacheModel1];

// cacheModel2
VideoCacheModel *cacheModel2 = [[VideoCacheModel alloc] init];
TXPlayerDrmBuilder *drmBuilder2 = [[TXPlayerDrmBuilder alloc] init];
drmBuilder2.deviceCertificateUrl = @"https://cert.drm.vod-qcloud.com/cert/v1/59ca267fdd87903b933cb845b844eda2/fairplay.cer";
drmBuilder2.keyLicenseUrl = @"https://fairplay-test.drm.vod-qcloud.com/fairplay/getlicense/v2?drmToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIjoiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxMzc4OCwiZmlsZUlkIjoiNTI4Nzg1MjEwOTg0OTE1NDY1OSIsImN1cnJlbnRUaW1lU3RhbXAiOjAsImV4cGlyZVRpbWVTdGFtcCI6Mjk2MDk5NTE3MCwicmFuZG9tIjowLCJvdmVybGF5S2V5IjoiIiwib3ZlcmxheUl2IjoiIiwiY2lwaGVyZWRPdmVybGF5S2V5IjoiIiwiY2lwaGVyZWRPdmVybGF5SXYiOiIiLCJrZXlJZCI6MCwic3RyaWN0TW9kZSI6MCwicGVyc2lzdGVudCI6Ik9OIiwicmVudGFsRHVyYXRpb24iOjYwMH0~Wnj6epGrf_drf9AOTGBfF1QOIEQVGN0A0_Hjty_kOUk";
drmBuilder2.playUrl = @"https://1500013788.vod2.myqcloud.com/43953aebvodtranscq1500013788/e57605175287852109849154659/adp.153829.m3u8";
cacheModel2.drmBuilder = drmBuilder2;
cacheModel2.videoTitle = @"FairPlay HLS(license 有效期为10分钟)";
[self.videoArray addObject:cacheModel2];

[self.tableView reloadData];
}

@@ -431,7 +451,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
dataSource.pSign = model.pSign;
dataSource.quality = [self getCurrentQuality];
mediaInfo.dataSource = dataSource;
[self.manager startDownload:mediaInfo];
// 启动下载
if (!model.drmBuilder) {
[self.manager startDownload:mediaInfo];
} else {
[self.manager startDownloadWithDRMBuilder:model.drmBuilder];
}
}
}
}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@

#import <Foundation/Foundation.h>
#import "DownloadCallback.h"
#import "TXPlayerDrmBuilder.h"

NS_ASSUME_NONNULL_BEGIN

@@ -42,6 +43,8 @@ NS_ASSUME_NONNULL_BEGIN

- (void)startDownload:(TXVodDownloadMediaInfo *)mediaInfo;

- (void)startDownloadWithDRMBuilder:(TXPlayerDrmBuilder *)drmBuilder;

- (void)stopDownload:(TXVodDownloadMediaInfo *)mediaInfo;

- (void)setDownloadPath:(NSString *)path;
Original file line number Diff line number Diff line change
@@ -57,6 +57,10 @@ - (void)startDownload:(TXVodDownloadMediaInfo *)mediaInfo {
[self.manager startDownload:mediaInfo.dataSource];
}

- (void)startDownloadWithDRMBuilder:(TXPlayerDrmBuilder *)drmBuilder {
[self.manager startDownloadDrm:drmBuilder resolution:-1 userName:@"default"];
}

- (void)stopDownload:(TXVodDownloadMediaInfo *)mediaInfo {
[self.manager stopDownload:mediaInfo];
}
Original file line number Diff line number Diff line change
@@ -136,38 +136,47 @@ - (void)loadDashVideoData {

TXVideoModel *model1 = [[TXVideoModel alloc] init];
model1.videourl = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.20.mpd";
model1.duration = @"90";
[array addObject:model1];

TXVideoModel *model2 = [[TXVideoModel alloc] init];
model2.videourl = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.22.mpd";
model2.duration = @"90";
[array addObject:model2];

TXVideoModel *model3 = [[TXVideoModel alloc] init];
model3.videourl = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.1163819.mpd";
model3.duration = @"90";
[array addObject:model3];

TXVideoModel *model4 = [[TXVideoModel alloc] init];
model4.videourl = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.1163820.mpd";
model4.duration = @"90";
[array addObject:model4];

TXVideoModel *model5 = [[TXVideoModel alloc] init];
model5.videourl = @"http://1500004424.vod2.myqcloud.com/4383a13evodtranscq1500004424/baff45348602268011141077324/adp.9101.mpd";
model5.duration = @"90";
[array addObject:model5];

TXVideoModel *model6 = [[TXVideoModel alloc] init];
model6.videourl = @"https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd";
model6.duration = @"210";
[array addObject:model6];

TXVideoModel *model7 = [[TXVideoModel alloc] init];
model7.videourl = @"https://dash.akamaized.net/dash264/TestCases/2c/qualcomm/1/MultiResMPEG2.mpd";
model7.duration = @"654";
[array addObject:model7];

TXVideoModel *model8 = [[TXVideoModel alloc] init];
model8.videourl = @"https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
model8.duration = @"634";
[array addObject:model8];

TXVideoModel *model9 = [[TXVideoModel alloc] init];
model9.videourl = @"https://dash.akamaized.net/akamai/test/caption_test/ElephantsDream/elephants_dream_480p_heaac5_1_https.mpd";
model9.duration = @"653";
[array addObject:model9];

[self.videosArray removeAllObjects];
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ @interface SuperShortVideoView()<TXVideoPlayerDelegate, UITableViewDelegate, UIT

@property (nonatomic, assign) NSInteger currentPlayIndex;

@property (nonatomic, strong) TXVideoModel *currentPlayingModel;

@end

@implementation SuperShortVideoView
@@ -288,6 +290,7 @@ - (void)handleScrollPlaying:(UIScrollView *)scrollView {
- (void)getVideoPlayer:(TXVideoModel *)currentModel preloadOtherPlayer:(NSArray *)modelArray {
[[TXPlayerCacheManager shareInstance] updatePlayerCache:modelArray];
if (currentModel != nil) {
self.currentPlayingModel = currentModel;
self.currentPlayer = [[TXPlayerCacheManager shareInstance] getVideoPlayer:currentModel];
self.currentPlayer.delegate = self;
if (self.playmode == TXVideoPlayModeOneLoop) {
@@ -428,6 +431,9 @@ - (void)player:(TXVideoPlayer *)player currentTime:(float)currentTime totalTime:
dispatch_async(dispatch_get_main_queue(), ^{
STRONGIFY(self);
[self.currentPlayingCell setProgress:progress];
if( [self.currentPlayingModel.duration floatValue] == 0) {
self.currentPlayingModel.duration = [NSString stringWithFormat:@"%f", totalTime];
}
int intCurrentTime = currentTime;
int intTotalTime = totalTime;
if (intCurrentTime <= intTotalTime) {

0 comments on commit 907042f

Please sign in to comment.