Skip to content

Commit

Permalink
1、Upgrade demo and SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyanzhang committed Jul 25, 2022
1 parent 56df5f4 commit 4b1363b
Show file tree
Hide file tree
Showing 19 changed files with 414 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def common_pods_all
pod 'AFNetworking'
pod 'BlocksKit', '~> 2.2.5'
pod 'CWStatusBarNotification', '~> 2.3.5'
pod 'TXLiteAVSDK_Player', '~> 10.3.11513'
pod 'TXLiteAVSDK_Player', '10.4.11617'
end

def common_pods_smart
Expand Down
6 changes: 6 additions & 0 deletions Demo/TXLiteAVDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
D6BEF7ED2040362B00CBE2BD /* danmakufile in Resources */ = {isa = PBXBuildFile; fileRef = D6BEF79D204035CB00CBE2BD /* danmakufile */; };
D6BEF8222040368000CBE2BD /* ListVideoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D6BEF7242040353E00CBE2BD /* ListVideoCell.m */; };
D6BEF8232040368000CBE2BD /* MoviePlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D6BEF7262040353E00CBE2BD /* MoviePlayerViewController.m */; };
EDA70D95288E74FB00A9E10B /* FeedRequestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = EDA70D93288E74FB00A9E10B /* FeedRequestUtil.m */; };
EDC1B2B92847C9A60077A920 /* VideoCacheModel.m in Sources */ = {isa = PBXBuildFile; fileRef = EDC1B2A32847C9A60077A920 /* VideoCacheModel.m */; };
EDC1B2BA2847C9A60077A920 /* TXVodDownloadCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = EDC1B2A72847C9A60077A920 /* TXVodDownloadCenter.m */; };
EDC1B2BB2847C9A60077A920 /* DownloadCallback.m in Sources */ = {isa = PBXBuildFile; fileRef = EDC1B2A82847C9A60077A920 /* DownloadCallback.m */; };
Expand Down Expand Up @@ -379,6 +380,8 @@
D6BEF7262040353E00CBE2BD /* MoviePlayerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MoviePlayerViewController.m; sourceTree = "<group>"; };
D6BEF79D204035CB00CBE2BD /* danmakufile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = danmakufile; sourceTree = "<group>"; };
D6E5D1C020B7B61F00812B2F /* ReplayKit2Define.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReplayKit2Define.h; sourceTree = "<group>"; };
EDA70D93288E74FB00A9E10B /* FeedRequestUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FeedRequestUtil.m; sourceTree = "<group>"; };
EDA70D94288E74FB00A9E10B /* FeedRequestUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FeedRequestUtil.h; sourceTree = "<group>"; };
EDC1B2A32847C9A60077A920 /* VideoCacheModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VideoCacheModel.m; sourceTree = "<group>"; };
EDC1B2A52847C9A60077A920 /* DownloadCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadCallback.h; sourceTree = "<group>"; };
EDC1B2A62847C9A60077A920 /* TXVodDownloadCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TXVodDownloadCenter.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -839,6 +842,8 @@
isa = PBXGroup;
children = (
6BE60191272BE98E0011BE60 /* FeedVideoPlayMem.h */,
EDA70D94288E74FB00A9E10B /* FeedRequestUtil.h */,
EDA70D93288E74FB00A9E10B /* FeedRequestUtil.m */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1406,6 +1411,7 @@
D6BEF8222040368000CBE2BD /* ListVideoCell.m in Sources */,
17C0D193273BC641009910EC /* ScanQRController.mm in Sources */,
40A1DF63263841900011E532 /* UIColor+MLPFlatColors.m in Sources */,
EDA70D95288E74FB00A9E10B /* FeedRequestUtil.m in Sources */,
17EB761026E9BCCD00D09EC8 /* TXConfigManager.m in Sources */,
6BBFDC18272ACC84009950B6 /* SuperFeedPlayView.m in Sources */,
40A1DF8F2638419E0011E532 /* UIView+CustomAutoLayout.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#import "SuperFeedPlayView.h"
#import "FeedVideoPlayMem.h"
#import <Masonry/Masonry.h>

#import <SDWebImage/SDImageCache.h>
#import "FeedVideoModel.h"
#import "FeedRequestUtil.h"

@interface FeedPlayViewController ()<SuperFeedPlayViewDelegate, CAAnimationDelegate>

Expand Down Expand Up @@ -68,36 +69,44 @@ - (void)viewDidLoad {

// 初始化feedPlayView的子组件
[self.feedPlayView initChildView];

[self.feedPlayView setFeedData:[self loadTestData] isCleanData:YES];
}

#pragma mark - click
- (void)backClick {
[self.feedPlayView removeVideo];
[self.feedPlayView destory];
self.feedPlayView = nil;
[[SDImageCache sharedImageCache] clearMemory];
[self.navigationController popToRootViewControllerAnimated:NO];
}

#pragma mark - SuperFeedPlayViewDelegate
- (void)refreshNewFeedData {
[self.feedPlayView finishRefresh];
[self.feedPlayView setFeedData:[self getRandomArrFrome:[self loadTestData]] isCleanData:YES];
__weak typeof(self) weakSelf = self;
[self loadTestDataWithsuccess:^(NSMutableArray *list) {
[weakSelf.feedPlayView finishRefresh];
[weakSelf.feedPlayView setFeedData:[weakSelf getRandomArrFrome:list] isCleanData:YES];
}];
}

- (void)loadNewFeedDataWithPage:(NSInteger)page {
[self.feedPlayView finishLoadMore];
[self.feedPlayView setFeedData:[self getRandomArrFrome:[self loadTestData]] isCleanData:NO];
__weak typeof(self) weakSelf = self;
[self loadTestDataWithsuccess:^(NSMutableArray *list) {
[weakSelf.feedPlayView finishLoadMore];
[weakSelf.feedPlayView setFeedData:[weakSelf getRandomArrFrome:list] isCleanData:NO];
}];
}

- (void)showFeedDetailViewWithHeadModel:(FeedHeadModel *)model videoModel:(FeedVideoModel *)videoModel playView:(UIView *)superPlayView {
self.isPushToDetail = YES;
self.superPlayView = superPlayView;

FeedDetailViewController *detailVC = [[FeedDetailViewController alloc] init];
__block FeedDetailViewController *detailVC = [[FeedDetailViewController alloc] init];
detailVC.headModel = model;
detailVC.superPlayView = superPlayView;
detailVC.detailListData = [self loadTestData];
[self loadTestDataWithsuccess:^(NSMutableArray *list) {
detailVC.detailListData = list;
}];
detailVC.videoModel = videoModel;
[self.navigationController pushViewController:detailVC animated:NO];
}
Expand All @@ -113,7 +122,32 @@ - (SuperFeedPlayView *)feedPlayView {
}

#pragma mark - 测试数据
- (NSMutableArray *)loadTestData {
- (void)loadTestDataWithsuccess:(void(^)(NSMutableArray *list))success {
NSMutableArray *result = [self loadVideoData];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_group_t downloadVideoGroup = dispatch_group_create();
[result enumerateObjectsUsingBlock:^(FeedVideoModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
dispatch_group_enter(downloadVideoGroup);
[FeedRequestUtil getPlayInfo:(int)obj.appId
fileId:obj.fileId
psign:obj.pSign
completion:^(NSMutableDictionary * _Nonnull dic, NSError * _Nonnull error) {
obj.videoURL = [dic objectForKey:@"videoUrl"];
obj.multiVideoURLs = [dic objectForKey:@"multiVideoURLs"];
dispatch_group_leave(downloadVideoGroup);
}];
}];

dispatch_group_notify(downloadVideoGroup, dispatch_get_main_queue(), ^{
if (success && result.count > 0) {
success(result);
}
});
});
}

- (NSMutableArray *)loadVideoData {
NSMutableArray *result = [NSMutableArray array];

FeedVideoModel *model1 = [FeedVideoModel new];
Expand Down
7 changes: 7 additions & 0 deletions Demo/TXLiteAVDemo/SuperPlayFeedDemo/Model/FeedVideoModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <Foundation/Foundation.h>
#import "FeedHeadModel.h"
#import "SuperPlayerUrl.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -24,6 +25,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) NSString *videoIntroduce;
@property (nonatomic, strong) NSString *videoDesStr;

@property (nonatomic, strong) NSString *pSign;

@property (nonatomic, strong) NSString *videoURL;

@property(nonatomic, strong) NSArray<SuperPlayerUrl *> *multiVideoURLs;

@end

NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions Demo/TXLiteAVDemo/SuperPlayFeedDemo/Utils/FeedRequestUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FeedRequestUtil.h
// TXLiteAVDemo
//
// Created by 路鹏 on 2022/6/17.
// Copyright © 2022 Tencent. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface FeedRequestUtil : NSObject

+ (void)getPlayInfo:(int)appId
fileId:(NSString *)fileId
psign:(NSString *)psign
completion:(void (^)(NSMutableDictionary *dic, NSError *error))completion;

@end

NS_ASSUME_NONNULL_END
209 changes: 209 additions & 0 deletions Demo/TXLiteAVDemo/SuperPlayFeedDemo/Utils/FeedRequestUtil.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
//
// FeedRequestUtil.m
// TXLiteAVDemo
//
// Created by 路鹏 on 2022/6/17.
// Copyright © 2022 Tencent. All rights reserved.
//

#import "FeedRequestUtil.h"
#import "J2Obj.h"
#import "SuperPlayerUrl.h"

#define BASE_URL @"http://playvideo.qcloud.com/getplayinfo/v4"

@implementation FeedRequestUtil

+ (void)getPlayInfo:(int)appId
fileId:(NSString *)fileId
psign:(NSString *)psign
completion:(void (^)(NSMutableDictionary *dic, NSError *error))completion {
if (appId == 0 || fileId.length == 0) {
if (completion) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class])
code:-1
userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"parameter error"]}];
completion(nil, error);
}
}

NSMutableDictionary *params = [NSMutableDictionary dictionary];

if (psign) {
params[@"psign"] = psign;
}

NSString *httpBodyString = [self makeParamtersString:params withEncoding:NSUTF8StringEncoding];
NSString *urlStr = [NSString stringWithFormat:@"%@/%ld/%@", BASE_URL, (long)appId, fileId];
if (httpBodyString) {
urlStr = [urlStr stringByAppendingFormat:@"?%@", httpBodyString];
}
NSURL *url = [NSURL URLWithString:urlStr];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLSessionConfiguration *defaultConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:defaultConfig delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
if (error) {
if (completion) {
completion(nil, error);
}
}

if (data.length == 0) {
if (completion) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class])
code:-1
userInfo:@{NSLocalizedDescriptionKey : @"request error", NSLocalizedFailureReasonErrorKey : @"content is nil"}];
completion(nil, error);
}
}

@try {
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableLeaves) error:&error];
if (dict == nil) {
if (completion) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class])
code:-2
userInfo:@{NSLocalizedDescriptionKey : @"invalid format"}];
completion(nil, error);
}
}

if ([dict objectForKey:@"code"]) {
int code = [[dict objectForKey:@"code"] intValue];
if (code != 0) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class])
code:code
userInfo:@{NSLocalizedDescriptionKey : dict[@"message"]}];
completion(nil, error);
}
}

NSMutableDictionary *dic = [NSMutableDictionary dictionary];
int ver = dict[@"version"] ? J2Num(dict[@"version"]).intValue : 2;
if (ver == 2) {
NSString *url = @"";
NSMutableArray *multiVideoURLs = [self makeV2UrlWithUrl:url response:dict];
if (url.length > 0) {
[dic setObject:url forKey:@"videoUrl"];
}
[dic setObject:multiVideoURLs forKey:@"multiVideoURLs"];

} else {
NSString *url = [self makeV4Urlwithresponse:dict];
if (url.length > 0) {
[dic setObject:url forKey:@"videoUrl"];
}
}

if (completion) {
completion(dic, nil);
}

} @catch (NSException *exception) {
if (completion) {
NSError *error = [NSError errorWithDomain:NSStringFromClass([self class])
code:-2
userInfo:@{NSLocalizedDescriptionKey : @"invalid format"}];
completion(nil, error);
}
}
}];

[dataTask resume];
}

+ (NSString *)makeParamtersString:(NSDictionary *)parameters withEncoding:(NSStringEncoding)encoding {
if (nil == parameters || [parameters count] == 0) return nil;

NSMutableString *stringOfParamters = [[NSMutableString alloc] init];
NSEnumerator * keyEnumerator = [parameters keyEnumerator];
id key = nil;
while ((key = [keyEnumerator nextObject])) {
[stringOfParamters appendFormat:@"%@=%@&", key, [parameters valueForKey:key]];
}

// Delete last character of '&'
NSRange lastCharRange = {[stringOfParamters length] - 1, 1};
[stringOfParamters deleteCharactersInRange:lastCharRange];
return stringOfParamters;
}


// 获取URL
+ (NSString *)makeV4Urlwithresponse:(NSDictionary *)dict {
NSDictionary *media = dict[@"media"];
NSString* audioVideoType = [media valueForKey:@"audioVideoType"];
NSDictionary *streamInfo = [self getStreamInfo:audioVideoType media:media];
//解析视频播放url
NSString *url = streamInfo[@"url"];
return url;
}

+ (NSDictionary *)getStreamInfo:(NSString*) audioVideoType media:(NSDictionary*) media{
NSDictionary *streamInfo;
if ([audioVideoType isEqualToString:@"Original"]) { //原视频输出
streamInfo = [media valueForKey:@"originalInfo"];
}else if ([audioVideoType isEqualToString:@"Transcode"]){ //转码输出
streamInfo = [media valueForKey:@"transcodeInfo"];
}else{ //自适应码流输出
streamInfo = [media valueForKeyPath:@"streamingInfo.plainOutput"];
}
return streamInfo;;
}


+ (NSMutableArray *)makeV2UrlWithUrl:(NSString *)url response:(NSDictionary *)dict {
NSString * masterUrl = J2Str([dict valueForKeyPath:@"videoInfo.masterPlayList.url"]);
NSMutableArray<SuperPlayerUrl *> *result = [NSMutableArray new];
if (masterUrl.length > 0) {
url = masterUrl;
} else {
NSString *mainDefinition = J2Str([dict valueForKeyPath:@"playerInfo.defaultVideoClassification"]);
NSArray *videoClassification = J2Array([dict valueForKeyPath:@"playerInfo.videoClassification"]);
NSArray *transcodeList = J2Array([dict valueForKeyPath:@"videoInfo.transcodeList"]);

for (NSDictionary *transcode in transcodeList) {
SuperPlayerUrl *subModel = [SuperPlayerUrl new];
subModel.url = J2Str(transcode[@"url"]);
NSNumber *theDefinition = J2Num(transcode[@"definition"]);

for (NSDictionary *definition in videoClassification) {
for (NSObject *definition2 in J2Array([definition valueForKeyPath:@"definitionList"])) {
if ([definition2 isEqual:theDefinition]) {
subModel.title = J2Str([definition valueForKeyPath:@"name"]);
NSString *definitionId = J2Str([definition valueForKeyPath:@"id"]);
// 初始播放清晰度
if ([definitionId isEqualToString:mainDefinition]) {
url = subModel.url;
}
break;
}
}
}
// 同一个清晰度可能存在多个转码格式,这里只保留一种格式,且优先mp4类型
for (SuperPlayerUrl *item in result) {
if ([item.title isEqual:subModel.title]) {
if (![item.url containsString:@".mp4"]) {
item.url = subModel.url;
}
subModel = nil;
break;
}
}

if (subModel) {
[result addObject:subModel];
}
}
}

return result;
}

@end
Loading

0 comments on commit 4b1363b

Please sign in to comment.