Skip to content

Commit 5c04ca2

Browse files
author
dokieyang
committed
add api example
1 parent 23bde03 commit 5c04ca2

File tree

212 files changed

+8347
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+8347
-0
lines changed

Player-API-Example-iOS/PlayerApiDemo/PlayerApiDemo.xcodeproj/project.pbxproj

Lines changed: 1169 additions & 0 deletions
Large diffs are not rendered by default.

Player-API-Example-iOS/PlayerApiDemo/PlayerApiDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// AppDelegate.h
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import <UIKit/UIKit.h>
9+
10+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
11+
12+
@property(nonatomic, strong) UIWindow *window;
13+
14+
@end
15+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// AppDelegate.m
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import "AppDelegate.h"
9+
#import "MainViewController.h"
10+
#import "TXApiConfigManager.h"
11+
#import <TXLiteAVSDK_Player/TXLiveBase.h>
12+
13+
@interface AppDelegate ()
14+
15+
@property (nonatomic, strong) MainViewController *mainViewController;
16+
17+
@end
18+
19+
@implementation AppDelegate
20+
21+
22+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
23+
// Override point for customization after application launch.
24+
25+
[[TXApiConfigManager shareInstance] loadConfig];
26+
27+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
28+
self.window.backgroundColor = [UIColor whiteColor];
29+
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, 0) forBarMetrics:UIBarMetricsDefault];
30+
if (@available(iOS 13.0, *)) {
31+
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
32+
}
33+
34+
UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
35+
self.window.rootViewController = navc;
36+
37+
[self.window makeKeyAndVisible];
38+
39+
// 设置licence
40+
[TXLiveBase setLicenceURL:@"https://license-test.vod2.myqcloud.com/test/license/testV2/1253968938_1/v_cube.license" key:@"79aa077679db4b0d68643e7af3516719"];
41+
42+
return YES;
43+
}
44+
45+
- (MainViewController *)mainViewController {
46+
if (!_mainViewController) {
47+
_mainViewController = [[MainViewController alloc] init];
48+
}
49+
return _mainViewController;
50+
}
51+
52+
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// TXApiConfigManager.h
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
#import "TXAppHomeModel.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface TXApiConfigManager : NSObject
14+
15+
+ (instancetype)shareInstance;
16+
17+
// 加载配置文件
18+
- (void)loadConfig;
19+
20+
//获取菜单配置
21+
- (NSMutableArray<TXAppHomeModel *> *)getMenuConfig;
22+
23+
@end
24+
25+
NS_ASSUME_NONNULL_END
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// TXApiConfigManager.m
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import "TXApiConfigManager.h"
9+
#import "TXHomeCellModel.h"
10+
11+
static TXApiConfigManager *_shareInstance = nil;
12+
13+
@interface TXApiConfigManager()
14+
15+
@property (nonatomic, strong) NSDictionary *configDic;
16+
@property(nonatomic, weak) id actionTarget;
17+
18+
@end
19+
20+
@implementation TXApiConfigManager
21+
22+
+ (instancetype)shareInstance {
23+
static dispatch_once_t predicate;
24+
dispatch_once(&predicate, ^{
25+
_shareInstance = [[TXApiConfigManager alloc] init];
26+
});
27+
return _shareInstance;
28+
}
29+
30+
- (void)loadConfig {
31+
NSString *plistName = @"Player";
32+
NSString *filePath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
33+
_configDic = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
34+
}
35+
36+
- (NSMutableArray<TXAppHomeModel *> *)getMenuConfig {
37+
NSMutableArray<TXAppHomeModel *> *cellInfos = [NSMutableArray array];
38+
NSArray *menusConfig = [self menusConfig];
39+
for (NSDictionary *menu in menusConfig) {
40+
41+
TXAppHomeModel *homeModel = [[TXAppHomeModel alloc] init];
42+
homeModel.type = [menu objectForKey:@"type"];
43+
44+
NSArray *subMenus = [menu objectForKey:@"module"];
45+
NSMutableArray *subCells = [NSMutableArray array];
46+
for (NSDictionary *subMenu in subMenus) {
47+
TXHomeCellModel *cellModel = [[TXHomeCellModel alloc] init];
48+
cellModel.title = [subMenu objectForKey:@"title"];
49+
cellModel.desc = [subMenu objectForKey:@"desc"];
50+
cellModel.classStr = [subMenu objectForKey:@"class"];
51+
52+
[subCells addObject:cellModel];
53+
}
54+
55+
homeModel.homeModels = subCells;
56+
[cellInfos addObject:homeModel];
57+
}
58+
59+
return cellInfos;
60+
}
61+
62+
- (NSArray *)menusConfig {
63+
return [_configDic objectForKey:@"menuConfig"];
64+
}
65+
66+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// MainViewController.h
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import <UIKit/UIKit.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface MainViewController : UIViewController
13+
14+
@end
15+
16+
NS_ASSUME_NONNULL_END
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//
2+
// MainViewController.m
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import "MainViewController.h"
9+
#import "TXHomeTableViewCell.h"
10+
#import "TXHomeCellModel.h"
11+
#import "TXApiConfigManager.h"
12+
#import "TXAppModuleMacro.h"
13+
#import "TXAppLocalized.h"
14+
15+
@interface MainViewController ()<UITableViewDelegate, UITableViewDataSource>
16+
17+
@property (nonatomic, strong) UITableView *tableView;
18+
@property (nonatomic, strong) NSMutableArray *homeData;
19+
20+
@end
21+
22+
@implementation MainViewController
23+
24+
- (void)viewDidLoad {
25+
[super viewDidLoad];
26+
// Do any additional setup after loading the view.
27+
self.view.backgroundColor = TX_RGBA(28,28,30,1);
28+
self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
29+
30+
[self loadHomeData];
31+
32+
[self setupNaviBarStatus];
33+
34+
[self.view addSubview:self.tableView];
35+
}
36+
37+
- (void)loadHomeData {
38+
self.homeData = [[TXApiConfigManager shareInstance] getMenuConfig];
39+
}
40+
41+
- (void)setupNaviBarStatus {
42+
self.navigationItem.title = Localize(@"PLAYER-API-EXAMPLE.Home.Title");
43+
[self.navigationController setNavigationBarHidden:false animated:false];
44+
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
45+
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
46+
self.navigationController.navigationBar.translucent = YES;
47+
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
48+
}
49+
50+
#pragma mark - 懒加载
51+
52+
- (UITableView *)tableView {
53+
if (!_tableView) {
54+
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, TX_NavBarAndStatusBarHeight, TX_SCREEN_WIDTH, TX_SCREEN_HEIGHT - TX_NavBarAndStatusBarHeight)];
55+
_tableView.scrollsToTop = NO;
56+
_tableView.backgroundColor = TX_ClearColor;
57+
_tableView.delegate = self;
58+
_tableView.dataSource = self;
59+
_tableView.estimatedRowHeight = 0;
60+
_tableView.showsVerticalScrollIndicator = NO;
61+
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
62+
[_tableView registerClass:[TXHomeTableViewCell class] forCellReuseIdentifier:TXHomeTableViewCellReuseIdentify];
63+
if (@available(iOS 11.0, *)) {
64+
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
65+
}
66+
}
67+
return _tableView;
68+
}
69+
70+
#pragma mark - UITableViewDataSource
71+
72+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
73+
return self.homeData.count;
74+
}
75+
76+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
77+
TXAppHomeModel *homeModel = self.homeData[section];
78+
NSArray *homeArray = homeModel.homeModels;
79+
return homeArray.count;
80+
}
81+
82+
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
83+
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)];
84+
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, headerView.bounds.size.width, 40)];
85+
titleLabel.textColor = UIColor.whiteColor;
86+
titleLabel.font = [UIFont systemFontOfSize:16];
87+
TXAppHomeModel *homeModel = self.homeData[section];
88+
titleLabel.text = Localize(homeModel.type);
89+
[headerView addSubview:titleLabel];
90+
return headerView;
91+
}
92+
93+
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
94+
return 40;
95+
}
96+
97+
#pragma mark - UITableViewDelegate
98+
99+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
100+
101+
TXHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TXHomeTableViewCellReuseIdentify forIndexPath:indexPath];
102+
TXAppHomeModel *homeModel = self.homeData[indexPath.section];
103+
NSArray *homeArray = homeModel.homeModels;
104+
105+
[cell setHomeModel:homeArray[indexPath.row]];
106+
return cell;
107+
}
108+
109+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
110+
TXAppHomeModel *homeModel = self.homeData[indexPath.section];
111+
NSArray *homeArray = homeModel.homeModels;
112+
113+
TXHomeCellModel *homeCellModel = homeArray[indexPath.row];
114+
[self pushFeaturesViewController:homeCellModel.classStr];
115+
}
116+
117+
- (void)pushFeaturesViewController:(NSString *)className {
118+
Class class = NSClassFromString(className);
119+
if (class) {
120+
id controller = [[NSClassFromString(className) alloc] init];
121+
if (controller) {
122+
[self.navigationController pushViewController:controller animated:true];
123+
}
124+
}
125+
}
126+
127+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// TXAppLocalized.h
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
extern NSString *LocalizeFromTable(NSString *key, NSString *table);
13+
extern NSString *const Localize_TableName;
14+
extern NSString *Localize(NSString *key);
15+
16+
NS_ASSUME_NONNULL_END
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// TXAppLocalized.m
3+
// PlayerApiDemo
4+
//
5+
// Copyright (c) 2022 Tencent. All rights reserved.
6+
//
7+
8+
#import "TXAppLocalized.h"
9+
10+
NSString *LocalizeFromTable(NSString *key, NSString *table) {
11+
return [NSBundle.mainBundle localizedStringForKey:key value:@"" table:table];
12+
}
13+
14+
NSString *const Localize_TableName = @"TXHomeModuleLocalize";
15+
NSString *Localize(NSString *key) {
16+
return LocalizeFromTable(key, Localize_TableName);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
TXHomeModuleLocalize.strings
3+
PlayerApiDemo
4+
5+
Copyright (c) 2022 Tencent. All rights reserved.
6+
7+
*/
8+
9+
"PLAYER-API-EXAMPLE.Home.Title" = "Player API Example";
10+
11+
"PLAYER-API-Example.Home.FunctionsZone" = "Functions Zone";
12+
"PLAYER-API-Example.Home.BasicPlayer" = "Basic Player";
13+
"PLAYER-API-Example.Home.PreDownloadAndPreloading" = "PreDownload And Preloading";
14+
"PLAYER-API-Example.Home.SetSpeciResolution" = "Set specific Resolution";
15+
"PLAYER-API-Example.Home.SetStartTime" = "Set Start Time";
16+
"PLAYER-API-Example.Home.VideoDownload" = "Video Download";
17+
"PLAYER-API-Example.Home.ControlPanel" = "Control Panel";
18+
19+
20+
"PLAYER-API-Example.Home.ScenesZone" = "Scenes Zone";
21+
"PLAYER-API-Example.Home.ShortVideoPlay" = "Short Video Play";

0 commit comments

Comments
 (0)