Skip to content

Commit

Permalink
add api example
Browse files Browse the repository at this point in the history
  • Loading branch information
dokieyang committed Dec 26, 2022
1 parent 23bde03 commit 5c04ca2
Show file tree
Hide file tree
Showing 212 changed files with 8,347 additions and 0 deletions.
1,169 changes: 1,169 additions & 0 deletions Player-API-Example-iOS/PlayerApiDemo/PlayerApiDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property(nonatomic, strong) UIWindow *window;

@end

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// AppDelegate.m
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "TXApiConfigManager.h"
#import <TXLiteAVSDK_Player/TXLiveBase.h>

@interface AppDelegate ()

@property (nonatomic, strong) MainViewController *mainViewController;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

[[TXApiConfigManager shareInstance] loadConfig];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, 0) forBarMetrics:UIBarMetricsDefault];
if (@available(iOS 13.0, *)) {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
self.window.rootViewController = navc;

[self.window makeKeyAndVisible];

// 设置licence
[TXLiveBase setLicenceURL:@"https://license-test.vod2.myqcloud.com/test/license/testV2/1253968938_1/v_cube.license" key:@"79aa077679db4b0d68643e7af3516719"];

return YES;
}

- (MainViewController *)mainViewController {
if (!_mainViewController) {
_mainViewController = [[MainViewController alloc] init];
}
return _mainViewController;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// TXApiConfigManager.h
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

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

NS_ASSUME_NONNULL_BEGIN

@interface TXApiConfigManager : NSObject

+ (instancetype)shareInstance;

// 加载配置文件
- (void)loadConfig;

//获取菜单配置
- (NSMutableArray<TXAppHomeModel *> *)getMenuConfig;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// TXApiConfigManager.m
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import "TXApiConfigManager.h"
#import "TXHomeCellModel.h"

static TXApiConfigManager *_shareInstance = nil;

@interface TXApiConfigManager()

@property (nonatomic, strong) NSDictionary *configDic;
@property(nonatomic, weak) id actionTarget;

@end

@implementation TXApiConfigManager

+ (instancetype)shareInstance {
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
_shareInstance = [[TXApiConfigManager alloc] init];
});
return _shareInstance;
}

- (void)loadConfig {
NSString *plistName = @"Player";
NSString *filePath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
_configDic = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}

- (NSMutableArray<TXAppHomeModel *> *)getMenuConfig {
NSMutableArray<TXAppHomeModel *> *cellInfos = [NSMutableArray array];
NSArray *menusConfig = [self menusConfig];
for (NSDictionary *menu in menusConfig) {

TXAppHomeModel *homeModel = [[TXAppHomeModel alloc] init];
homeModel.type = [menu objectForKey:@"type"];

NSArray *subMenus = [menu objectForKey:@"module"];
NSMutableArray *subCells = [NSMutableArray array];
for (NSDictionary *subMenu in subMenus) {
TXHomeCellModel *cellModel = [[TXHomeCellModel alloc] init];
cellModel.title = [subMenu objectForKey:@"title"];
cellModel.desc = [subMenu objectForKey:@"desc"];
cellModel.classStr = [subMenu objectForKey:@"class"];

[subCells addObject:cellModel];
}

homeModel.homeModels = subCells;
[cellInfos addObject:homeModel];
}

return cellInfos;
}

- (NSArray *)menusConfig {
return [_configDic objectForKey:@"menuConfig"];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MainViewController.h
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface MainViewController : UIViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// MainViewController.m
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import "MainViewController.h"
#import "TXHomeTableViewCell.h"
#import "TXHomeCellModel.h"
#import "TXApiConfigManager.h"
#import "TXAppModuleMacro.h"
#import "TXAppLocalized.h"

@interface MainViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *homeData;

@end

@implementation MainViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = TX_RGBA(28,28,30,1);
self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;

[self loadHomeData];

[self setupNaviBarStatus];

[self.view addSubview:self.tableView];
}

- (void)loadHomeData {
self.homeData = [[TXApiConfigManager shareInstance] getMenuConfig];
}

- (void)setupNaviBarStatus {
self.navigationItem.title = Localize(@"PLAYER-API-EXAMPLE.Home.Title");
[self.navigationController setNavigationBarHidden:false animated:false];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
self.navigationController.navigationBar.translucent = YES;
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
}

#pragma mark - 懒加载

- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, TX_NavBarAndStatusBarHeight, TX_SCREEN_WIDTH, TX_SCREEN_HEIGHT - TX_NavBarAndStatusBarHeight)];
_tableView.scrollsToTop = NO;
_tableView.backgroundColor = TX_ClearColor;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 0;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_tableView registerClass:[TXHomeTableViewCell class] forCellReuseIdentifier:TXHomeTableViewCellReuseIdentify];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
return _tableView;
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.homeData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
TXAppHomeModel *homeModel = self.homeData[section];
NSArray *homeArray = homeModel.homeModels;
return homeArray.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 40)];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, headerView.bounds.size.width, 40)];
titleLabel.textColor = UIColor.whiteColor;
titleLabel.font = [UIFont systemFontOfSize:16];
TXAppHomeModel *homeModel = self.homeData[section];
titleLabel.text = Localize(homeModel.type);
[headerView addSubview:titleLabel];
return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}

#pragma mark - UITableViewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

TXHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TXHomeTableViewCellReuseIdentify forIndexPath:indexPath];
TXAppHomeModel *homeModel = self.homeData[indexPath.section];
NSArray *homeArray = homeModel.homeModels;

[cell setHomeModel:homeArray[indexPath.row]];
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TXAppHomeModel *homeModel = self.homeData[indexPath.section];
NSArray *homeArray = homeModel.homeModels;

TXHomeCellModel *homeCellModel = homeArray[indexPath.row];
[self pushFeaturesViewController:homeCellModel.classStr];
}

- (void)pushFeaturesViewController:(NSString *)className {
Class class = NSClassFromString(className);
if (class) {
id controller = [[NSClassFromString(className) alloc] init];
if (controller) {
[self.navigationController pushViewController:controller animated:true];
}
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TXAppLocalized.h
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

extern NSString *LocalizeFromTable(NSString *key, NSString *table);
extern NSString *const Localize_TableName;
extern NSString *Localize(NSString *key);

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// TXAppLocalized.m
// PlayerApiDemo
//
// Copyright (c) 2022 Tencent. All rights reserved.
//

#import "TXAppLocalized.h"

NSString *LocalizeFromTable(NSString *key, NSString *table) {
return [NSBundle.mainBundle localizedStringForKey:key value:@"" table:table];
}

NSString *const Localize_TableName = @"TXHomeModuleLocalize";
NSString *Localize(NSString *key) {
return LocalizeFromTable(key, Localize_TableName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
TXHomeModuleLocalize.strings
PlayerApiDemo

Copyright (c) 2022 Tencent. All rights reserved.

*/

"PLAYER-API-EXAMPLE.Home.Title" = "Player API Example";

"PLAYER-API-Example.Home.FunctionsZone" = "Functions Zone";
"PLAYER-API-Example.Home.BasicPlayer" = "Basic Player";
"PLAYER-API-Example.Home.PreDownloadAndPreloading" = "PreDownload And Preloading";
"PLAYER-API-Example.Home.SetSpeciResolution" = "Set specific Resolution";
"PLAYER-API-Example.Home.SetStartTime" = "Set Start Time";
"PLAYER-API-Example.Home.VideoDownload" = "Video Download";
"PLAYER-API-Example.Home.ControlPanel" = "Control Panel";


"PLAYER-API-Example.Home.ScenesZone" = "Scenes Zone";
"PLAYER-API-Example.Home.ShortVideoPlay" = "Short Video Play";
Loading

0 comments on commit 5c04ca2

Please sign in to comment.