diff --git a/Demo/TXLiteAVDemo.xcodeproj/project.pbxproj b/Demo/TXLiteAVDemo.xcodeproj/project.pbxproj index 3093ea8e..89e50374 100644 --- a/Demo/TXLiteAVDemo.xcodeproj/project.pbxproj +++ b/Demo/TXLiteAVDemo.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 17EB75EB26E9BC5200D09EC8 /* Player.plist in Resources */ = {isa = PBXBuildFile; fileRef = 17EB75B926E9BC5200D09EC8 /* Player.plist */; }; + 17EB761026E9BCCD00D09EC8 /* TXConfigManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 17EB760A26E9BCCC00D09EC8 /* TXConfigManager.m */; }; 400922B31F4FCC6E009B882D /* ScanQRController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 40F853561EE8FCDF00EE47D7 /* ScanQRController.mm */; }; 400922B71F4FCC6E009B882D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 40F853261EE8FC8400EE47D7 /* AppDelegate.m */; }; 400922BE1F4FCC6E009B882D /* AppLogMgr.m in Sources */ = {isa = PBXBuildFile; fileRef = 40F853281EE8FC8400EE47D7 /* AppLogMgr.m */; }; @@ -131,6 +133,16 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 17EB75B426E9BC5200D09EC8 /* Smart.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Smart.plist; sourceTree = ""; }; + 17EB75B526E9BC5200D09EC8 /* LIVE.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = LIVE.plist; sourceTree = ""; }; + 17EB75B626E9BC5200D09EC8 /* UGC.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = UGC.plist; sourceTree = ""; }; + 17EB75B826E9BC5200D09EC8 /* Enterprise.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Enterprise.plist; sourceTree = ""; }; + 17EB75B926E9BC5200D09EC8 /* Player.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Player.plist; sourceTree = ""; }; + 17EB75BB26E9BC5200D09EC8 /* Professional.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Professional.plist; sourceTree = ""; }; + 17EB75BC26E9BC5200D09EC8 /* International.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = International.plist; sourceTree = ""; }; + 17EB75BD26E9BC5200D09EC8 /* TRTC.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = TRTC.plist; sourceTree = ""; }; + 17EB760926E9BCCC00D09EC8 /* TXConfigManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TXConfigManager.h; sourceTree = ""; }; + 17EB760A26E9BCCC00D09EC8 /* TXConfigManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TXConfigManager.m; sourceTree = ""; }; 2840D91B24B8562200723FBC /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 400923B31F4FCC6E009B882D /* TXLiteAVDemo_Player.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TXLiteAVDemo_Player.app; sourceTree = BUILT_PRODUCTS_DIR; }; 401A9B3D247FCC7600C0763B /* AudioEffectSettingKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = AudioEffectSettingKit.xcodeproj; sourceTree = ""; }; @@ -230,6 +242,7 @@ 47E8CADB260B5C06001CF672 /* ColorMacro.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorMacro.h; sourceTree = ""; }; 47E8CCCE260C4EB2001CF672 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 47E8CCD6260C4EE3001CF672 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = ""; }; + 4FE10FF126F5D35A00DE6B9E /* BuglyOA.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = BuglyOA.framework; sourceTree = ""; }; 51A289F8230FB93A00B9B73F /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; 51A4AD391F1F8AE300B4A806 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; 7B4C917A24B4B0C80095C041 /* TXLaunchMoviePlayProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TXLaunchMoviePlayProtocol.h; sourceTree = ""; }; @@ -296,6 +309,21 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 17EB75B326E9BC5200D09EC8 /* config */ = { + isa = PBXGroup; + children = ( + 17EB75B426E9BC5200D09EC8 /* Smart.plist */, + 17EB75B526E9BC5200D09EC8 /* LIVE.plist */, + 17EB75B626E9BC5200D09EC8 /* UGC.plist */, + 17EB75B826E9BC5200D09EC8 /* Enterprise.plist */, + 17EB75B926E9BC5200D09EC8 /* Player.plist */, + 17EB75BB26E9BC5200D09EC8 /* Professional.plist */, + 17EB75BC26E9BC5200D09EC8 /* International.plist */, + 17EB75BD26E9BC5200D09EC8 /* TRTC.plist */, + ); + path = config; + sourceTree = ""; + }; 402A010A245070290037A219 /* BridgeHeader */ = { isa = PBXGroup; children = ( @@ -417,6 +445,8 @@ 40F853241EE8FC8400EE47D7 /* App */ = { isa = PBXGroup; children = ( + 4FE10FED26F5D28400DE6B9E /* Bugly */, + 17EB75B326E9BC5200D09EC8 /* config */, 47E8CCBC260C4090001CF672 /* TRTCInfoPlist */, 47E8CAAB260B5C05001CF672 /* AppCommon */, 4090F788246AE22000EA72A0 /* Main */, @@ -424,6 +454,8 @@ 402A010A245070290037A219 /* BridgeHeader */, 40F853251EE8FC8400EE47D7 /* AppDelegate.h */, 40F853261EE8FC8400EE47D7 /* AppDelegate.m */, + 17EB760926E9BCCC00D09EC8 /* TXConfigManager.h */, + 17EB760A26E9BCCC00D09EC8 /* TXConfigManager.m */, 40F853271EE8FC8400EE47D7 /* AppLogMgr.h */, 40F853281EE8FC8400EE47D7 /* AppLogMgr.m */, D6E5D1C020B7B61F00812B2F /* ReplayKit2Define.h */, @@ -629,6 +661,14 @@ path = TRTCInfoPlist; sourceTree = ""; }; + 4FE10FED26F5D28400DE6B9E /* Bugly */ = { + isa = PBXGroup; + children = ( + 4FE10FF126F5D35A00DE6B9E /* BuglyOA.framework */, + ); + path = Bugly; + sourceTree = ""; + }; 912A62052160D78A00C16E41 /* CFDanmaku */ = { isa = PBXGroup; children = ( @@ -842,6 +882,7 @@ 4009238F1F4FCC6E009B882D /* Main.storyboard in Resources */, 47E8C8B2260AECC4001CF672 /* UGCLocalized.strings in Resources */, D6BEF7ED2040362B00CBE2BD /* danmakufile in Resources */, + 17EB75EB26E9BC5200D09EC8 /* Player.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -902,6 +943,7 @@ 40A1DF372638415A0011E532 /* UIButton+Additions.m in Sources */, D6BEF8222040368000CBE2BD /* ListVideoCell.m in Sources */, 40A1DF63263841900011E532 /* UIColor+MLPFlatColors.m in Sources */, + 17EB761026E9BCCD00D09EC8 /* TXConfigManager.m in Sources */, 40A1DF8F2638419E0011E532 /* UIView+CustomAutoLayout.m in Sources */, 4053392724654D2700A6B478 /* TCHttpUtil.m in Sources */, D6BEF8232040368000CBE2BD /* MoviePlayerViewController.m in Sources */, diff --git a/Demo/TXLiteAVDemo/App/AppDelegate.m b/Demo/TXLiteAVDemo/App/AppDelegate.m index 8c793a9a..33740069 100644 --- a/Demo/TXLiteAVDemo/App/AppDelegate.m +++ b/Demo/TXLiteAVDemo/App/AppDelegate.m @@ -8,8 +8,7 @@ #import "AppDelegate.h" -#import - +#import "TXConfigManager.h" #import "AppLocalized.h" #ifdef ENABLE_TRTC @@ -55,8 +54,6 @@ #import "TXLaunchMoviePlayProtocol.h" #endif -#define BUGLY_APP_ID @"0" - NSString *helpUrlDb[] = { [Help_MLVBLiveRoom] = @"https://cloud.tencent.com/document/product/454/14606", [Help_录屏直播] = @"https://cloud.tencent.com/document/product/454/7883", @@ -107,6 +104,7 @@ - (void)clickHelp:(UIButton *)sender { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.didLaunched = YES; + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"remove_cache_preference"]) { NSFileManager *fm = [NSFileManager defaultManager]; NSString * documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; @@ -115,71 +113,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"remove_cache_preference"]; } [self registNotificaiton]; - //启动bugly组件,bugly组件为腾讯提供的用于crash上报和分析的开放组件,如果您不需要该组件,可以自行移除 - BuglyConfig *config = [[BuglyConfig alloc] init]; - NSString * version = nil; -#if ENABLE_TRTC - version = [TRTCCloud getSDKVersion]; -#else -#ifdef LIVE - version = [V2TXLivePremier getSDKVersionStr]; -#else - version = [TXLiveBase getSDKVersionStr]; -#endif -#endif - -#if DEBUG - config.debugMode = YES; -#endif - NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; - config.version = appVersion; - config.channel = @"LiteAV Demo"; - - [Bugly startWithAppId:BUGLY_APP_ID config:config]; -#ifdef ENABLE_UGC - [TXUGCBase setLicenceURL:@"" key:@""]; -#endif - -#if (defined(ENABLE_PUSH) || defined(ENABLE_INTERNATIONAL)) && !defined(TRTC) -#ifdef LIVE - [V2TXLivePremier setLicence:@"" key:@""]; -#else - [TXLiveBase setLicenceURL:@"" key:@""]; -#endif -#endif - -#ifdef TRTC - [TXLiveBase setLicenceURL:@"" key:@""]; -#endif - - NSLog(@"rtmp demo init crash report"); + + [[TXConfigManager shareInstance] loadConfig]; + [[TXConfigManager shareInstance] setLicence]; + [[TXConfigManager shareInstance] setLogConfig]; + [[TXConfigManager shareInstance] setupBugly]; // Override point for customization after application launch. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.backgroundColor = [UIColor whiteColor]; - -#ifdef ENABLE_TRTC - [TRTCCloud setConsoleEnabled:NO]; - [TRTCCloud setLogLevel:TRTCLogLevelDebug]; - [TRTCCloud setLogDelegate:[AppLogMgr shareInstance]]; -#else - //初始化log模块 -#ifndef UGC_SMART -#ifndef LIVE - [TXLiveBase sharedInstance].delegate = [AppLogMgr shareInstance]; - [TXLiveBase setConsoleEnabled:NO]; - [TXLiveBase setAppID:@""]; -#else - [V2TXLivePremier setObserver:[AppLogMgr shareInstance]]; - V2TXLiveLogConfig *logConf = [V2TXLiveLogConfig new]; - logConf.enableObserver = YES; - [V2TXLivePremier setLogConfig:logConf]; -#endif -#endif -#endif [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, 0) forBarMetrics:UIBarMetricsDefault]; - [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; [[UINavigationBar appearance] setBarTintColor:UIColor.blackColor]; [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; @@ -191,12 +134,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( #else [self showLoginController]; #endif - + [self.window makeKeyAndVisible]; #ifndef ENABLE_TRTC [[AFNetworkReachabilityManager sharedManager] startMonitoring]; #endif - #if !defined(PLAYER) && !defined(UGC) // 自定义 APP 未读数 [[V2TIMManager sharedInstance] setAPNSListener:self]; diff --git a/Demo/TXLiteAVDemo/App/Info.plist b/Demo/TXLiteAVDemo/App/Info.plist index 36a09ced..e76f47ca 100644 --- a/Demo/TXLiteAVDemo/App/Info.plist +++ b/Demo/TXLiteAVDemo/App/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 9.1.1219 + 9.2.1306 CFBundleSignature ???? CFBundleURLTypes @@ -36,7 +36,7 @@ CFBundleVersion - 1219 + 1306 IMSDKCrashReporterEnable LSRequiresIPhoneOS diff --git a/Demo/TXLiteAVDemo/App/Main/MainViewController.m b/Demo/TXLiteAVDemo/App/Main/MainViewController.m index bf680ee5..9a98f295 100644 --- a/Demo/TXLiteAVDemo/App/Main/MainViewController.m +++ b/Demo/TXLiteAVDemo/App/Main/MainViewController.m @@ -62,7 +62,7 @@ #endif #import "AppLocalized.h" - +#import "TXConfigManager.h" #define STATUS_BAR_HEIGHT [UIApplication sharedApplication].statusBarFrame.size.height static NSString *const XiaoZhiBoAppStoreURLString = @"http://itunes.apple.com/cn/app/id1132521667?mt=8"; @@ -84,12 +84,6 @@ @interface MainViewController () +#import "MainTableViewCell.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface TXConfigManager : NSObject ++ (instancetype)shareInstance; +- (void)loadConfig; +- (void)setLicence; +- (void)setLogConfig; +- (void)setupBugly; +- (NSMutableArray *)getMenuConfig; +- (void)setMenuActionTarget:(id)object; + +@end + +NS_ASSUME_NONNULL_END + diff --git a/Demo/TXLiteAVDemo/App/TXConfigManager.m b/Demo/TXLiteAVDemo/App/TXConfigManager.m new file mode 100644 index 00000000..3e2f5c8e --- /dev/null +++ b/Demo/TXLiteAVDemo/App/TXConfigManager.m @@ -0,0 +1,214 @@ +// +// TXConfigManager.m +// TXLiteAVDemo +// +// Created by origin 李 on 2021/9/6. +// Copyright © 2021 Tencent. All rights reserved. +// + +#ifdef ENTERPRISE +#import +#import +#endif + +#ifdef LIVE +#import "V2TXLivePremier.h" +#else +#import "TXLiveBase.h" +#endif + +#ifdef ENABLE_UGC +#import "TXUGCBase.h" +#endif + +#ifdef ENABLE_TRTC +#import "TRTCCloud.h" +#endif + +#import "AppLocalized.h" +#import "AppLogMgr.h" +#import "TCUtil.h" +#import "TXConfigManager.h" + +#define BUGLY_APP_ID @"afaa33f835" + +static TXConfigManager *_shareInstance = nil; + +@interface TXConfigManager () + +@property(nonatomic, strong) NSDictionary *config; +@property(nonatomic, weak) id actionTarget; + +@end + +@implementation TXConfigManager + ++ (instancetype)shareInstance { + static dispatch_once_t predicate; + dispatch_once(&predicate, ^{ + _shareInstance = [[TXConfigManager alloc] init]; + }); + return _shareInstance; +} + +- (void)setMenuActionTarget:(id)object { + self.actionTarget = object; +} + +- (void)loadConfig { + NSString *plistName; +#ifdef ENTERPRISE + plistName = @"Enterprise"; +#endif + +#ifdef PROFESSIONAL + plistName = @"Professional"; +#endif + +#ifdef ENABLE_INTERNATIONAL + plistName = @"International"; +#endif + +#ifdef PLAYER + plistName = @"Player"; +#endif + +#ifdef LIVE + plistName = @"LIVE"; +#endif + +#ifdef TRTC + plistName = @"TRTC"; +#endif + +#ifdef UGC + plistName = @"UGC"; +#endif + +#ifdef SMART + plistName = @"Smart"; +#endif + + NSString *filePath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"]; + _config = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; +} + +- (NSDictionary *)licenceConfig { + return [_config objectForKey:@"licenceConfig"]; +} + +- (NSArray *)menusConfig { + return [_config objectForKey:@"menuConfig"]; +} + +- (BOOL)enableBugly { + return [[_config objectForKey:@"enableBugly"] boolValue]; +} + +- (void)setLicence { +#if !defined(PLAYER) + NSString *licenceUrl = [self.licenceConfig objectForKey:@"licenceUrl"]; + NSString *licenceKey = [self.licenceConfig objectForKey:@"licenceKey"]; + //添加UGC模块的 +#ifdef ENABLE_UGC + [TXUGCBase setLicenceURL:licenceUrl key:licenceKey]; +#endif +#if !defined(UGC) +#ifdef LIVE + [V2TXLivePremier setLicence:licenceUrl key:licenceKey]; +#else + [TXLiveBase setLicenceURL:licenceUrl key:licenceKey]; +#endif +#endif +#endif +} + +- (void)setLogConfig { +#ifdef ENABLE_TRTC + [TRTCCloud setConsoleEnabled:NO]; + [TRTCCloud setLogLevel:TRTCLogLevelDebug]; + [TRTCCloud setLogDelegate:[AppLogMgr shareInstance]]; +#else +#ifdef LIVE + [V2TXLivePremier setObserver:[AppLogMgr shareInstance]]; + V2TXLiveLogConfig *logConf = [V2TXLiveLogConfig new]; + logConf.enableObserver = YES; + [V2TXLivePremier setLogConfig:logConf]; +#else + [TXLiveBase sharedInstance].delegate = [AppLogMgr shareInstance]; + [TXLiveBase setConsoleEnabled:NO]; + [TXLiveBase setAppID:@"1252463788"]; +#endif +#endif +} + +- (void)setupBugly { + if (![self enableBugly]) { + return; + } + +#if defined(ENTERPRISE) && !defined(DEBUG) + // 启动bugly组件,bugly组件为腾讯提供的用于crash上报和分析的开放组件,如果您不需要该组件,可以自行移除 + BuglyConfig *config = [[BuglyConfig alloc] init]; + NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + config.version = appVersion; + config.channel = @"LiteAV Release"; + [Bugly startWithAppId:BUGLY_APP_ID config:config]; + NSLog(@"rtmp demo init crash report"); +#endif +} + +- (NSMutableArray *)getMenuConfig { + NSMutableArray *cellInfos = [[NSMutableArray alloc] initWithCapacity:2]; + NSArray *menusConfig = [self menusConfig]; + for (NSDictionary *menu in menusConfig) { + bool debug = [menu objectForKey:@"debug"]; + if (debug && ![TCUtil getDEBUGSwitch]) { + continue; + } + NSString *title = [menu objectForKey:@"title"]; + CellInfo *cellInfo = [[CellInfo alloc] init]; + bool isTrtc = [menu objectForKey:@"TRTC"]; + cellInfo.title = V2Localize(title); + NSArray *subMenus = [menu objectForKey:@"subMenus"]; + NSMutableArray *subCells = [NSMutableArray array]; + for (NSDictionary *subMenu in subMenus) { + NSString *subTitle = [subMenu objectForKey:@"title"]; + NSString *classStr = [subMenu objectForKey:@"class"]; + bool debug = [subMenu objectForKey:@"debug"]; + if (debug && ![TCUtil getDEBUGSwitch]) { + continue; + } + if (isTrtc) { + subTitle = TRTCLocalize(subTitle); + } else { + subTitle = V2Localize(subTitle); + } + if (classStr.length > 0) { + CellInfo *subCellInfo = [CellInfo cellInfoWithTitle:subTitle + controllerClassName:classStr]; + [subCells addObject:subCellInfo]; + } else { + __weak __typeof(self) weakSelf = self; + CellInfo *subCellInfo = + [CellInfo cellInfoWithTitle:subTitle + actionBlock:^{ + NSString *method = [subMenu objectForKey:@"method"]; + SEL sel = NSSelectorFromString(method); + if ([weakSelf.actionTarget respondsToSelector:sel]) { + IMP imp = [weakSelf.actionTarget methodForSelector:sel]; + void (*func)(id, SEL) = (void *)imp; + func(weakSelf.actionTarget, sel); + } + }]; + [subCells addObject:subCellInfo]; + } + } + cellInfo.subCells = subCells; + [cellInfos addObject:cellInfo]; + } + return cellInfos; +} + +@end + diff --git a/Demo/TXLiteAVDemo/App/config/Player.plist b/Demo/TXLiteAVDemo/App/config/Player.plist new file mode 100644 index 00000000..6d028dc3 --- /dev/null +++ b/Demo/TXLiteAVDemo/App/config/Player.plist @@ -0,0 +1,29 @@ + + + + + licenceConfig + + licenceKey + ... + licenceUrl + ... + + menuConfig + + + subMenus + + + class + MoviePlayerViewController + title + MLVB.MainMenu.SuperPlayer + + + title + MLVB.MainMenu.Player + + + + diff --git a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.h b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.h index 32b237a1..2dbd9af9 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.h +++ b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.h @@ -25,6 +25,7 @@ @property NSString *url; @property NSArray *hdUrl; @property int type; // 0 - 点播;1 - 直播 +@property NSString *psign; - (void)addHdUrl:(NSString *)url withTitle:(NSString *)title; - (void)setModel:(SuperPlayerModel *)model; - (SuperPlayerModel *)getPlayerModel; diff --git a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.m b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.m index 2be30bed..5c2a0d83 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.m +++ b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/ListUI/ListVideoCell.m @@ -43,6 +43,7 @@ - (SuperPlayerModel *)getPlayerModel { SuperPlayerVideoId *videoId = [SuperPlayerVideoId new]; model.appId = [self appId]; videoId.fileId = [self fileId]; + videoId.psign = self.psign; model.videoId = videoId; model.videoURL = self.url; diff --git a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/MoviePlayerViewController.m b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/MoviePlayerViewController.m index 17008535..f1cfe6c1 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/MoviePlayerViewController.m +++ b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/MoviePlayerViewController.m @@ -33,6 +33,7 @@ __weak UITextField *appField; __weak UITextField *fileidField; __weak UITextField *urlField; +__weak UITextField *psignField; @interface MoviePlayerViewController () /** 播放器View的父视图*/ @@ -450,6 +451,7 @@ - (void)onNetSuccess:(TXMoviePlayInfoResponse *)playInfo { m.title = [NSString stringWithFormat:@"%@%@", LivePlayerLocalize(@"SuperPlayerDemo.MoviePlayer.video"), playInfo.fileId]; } m.coverUrl = playInfo.coverUrl; + m.psign = playInfo.pSign; [_vodDataSourceArray addObject:m]; dispatch_async(dispatch_get_main_queue(), ^{ [self.vodListView reloadData]; @@ -727,6 +729,11 @@ - (void)onAddClick:(UIButton *)btn { textField.placeholder = LivePlayerLocalize(@"SuperPlayerDemo.MoviePlayer.enterfileid"); fileidField = textField; }]; + + [control addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { + textField.placeholder = LivePlayerLocalize(@"SuperPlayerDemo.MoviePlayer.enterlivepsign"); + psignField = textField; + }]; } else { [control addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) { textField.placeholder = LivePlayerLocalize(@"SuperPlayerDemo.MoviePlayer.enterliveurl"); @@ -743,6 +750,9 @@ - (void)onAddClick:(UIButton *)btn { TXPlayerAuthParams *p = [TXPlayerAuthParams new]; p.appId = [appField.text intValue]; p.fileId = fileidField.text; + if (psignField.text.length > 0) { + p.sign = psignField.text; + } [self.authParamArray addObject:p]; [self getNextInfo]; diff --git a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayInfoResponse.h b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayInfoResponse.h index c2d254a3..0514796e 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayInfoResponse.h +++ b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayInfoResponse.h @@ -20,6 +20,7 @@ @property NSInteger appId; @property NSString *fileId; +@property NSString *pSign; - (instancetype)initWithResponse:(NSDictionary *)dict; diff --git a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayerNetApi.m b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayerNetApi.m index 7421a633..e09f35cd 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayerNetApi.m +++ b/Demo/TXLiteAVDemo/SuperPlayerDemo/SuperPlayer/TXMoviePlayerNetApi.m @@ -109,6 +109,7 @@ - (int)getplayinfo:(NSInteger)appId fileId:(NSString *)fileId psign:(NSString *) TXMoviePlayInfoResponse *playInfo = [[TXMoviePlayInfoResponse alloc] initWithResponse:dict]; playInfo.appId = appId; playInfo.fileId = fileId; + playInfo.pSign = psign; if (completion) { completion(playInfo, nil); } diff --git a/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModel.m b/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModel.m index 17e2ce15..078d7fcf 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModel.m +++ b/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModel.m @@ -6,6 +6,7 @@ #import "SPPlayCGIParser.h" #import "SuperPlayer.h" #import "SuperPlayerModelInternal.h" +#import const NSString *kPlayCGIHostname = @"playvideo.qcloud.com"; NSString *const kErrorDomain = @"SuperPlayerCGI"; @@ -33,14 +34,22 @@ - (void)dealloc { - (NSString *)playingDefinitionUrl { NSString *url; + // 获取初始播放清晰度url for (int i = 0; i < self.multiVideoURLs.count; i++) { if ([self.multiVideoURLs[i].title isEqualToString:self.playingDefinition]) { url = self.multiVideoURLs[i].url; + break; } } - if (url == nil) url = self.videoURL; + // 初始播放清晰度url获取失败,获取第一条转码流 if (url == nil) { - if (self.multiVideoURLs.count > 0) url = self.multiVideoURLs.firstObject.url; + if (self.multiVideoURLs.count > 0) { + url = self.multiVideoURLs.firstObject.url; + } + } + // 转码流获取失败,用原始地址 + if (url == nil) { + url = self.videoURL; } return url; } @@ -114,6 +123,10 @@ - (NSURLSessionTask *)requestWithCompletion:(void (^)(NSError *, SuperPlayerMode } Class parser = [SPPlayCGIParser parserOfVersion:responseVersion]; SPPlayCGIParseResult * result = [parser parseResponse:responseObject]; + if (responseVersion <= 2) { + self.overlayKey = nil; + self.overlayIv = nil; + } if (result == nil) { if (completion) { NSError *error = [NSError errorWithDomain:kErrorDomain code:kInvalidResponseErrorCode userInfo:@{NSLocalizedDescriptionKey : @"Invalid response."}]; @@ -149,6 +162,15 @@ - (NSDictionary *)_buildParams { if (self.videoId) { if (self.videoId.psign) { params[@"psign"] = self.videoId.psign; + self.overlayKey = [self _buildParamsRandomHexString]; + self.overlayIv = [self _buildParamsRandomHexString]; + NSString *cipheredOverlayKey = [self _buildParamsEncryptHexString:self.overlayKey]; + NSString *cipheredOverlayIv = [self _buildParamsEncryptHexString:self.overlayIv]; + if (cipheredOverlayKey.length > 0 && cipheredOverlayIv.length > 0) { + params[@"cipheredOverlayKey"] = cipheredOverlayKey; + params[@"cipheredOverlayIv"] = cipheredOverlayIv; + params[@"keyId"] = @"1"; + } } } else if (self.videoIdV2) { if (self.videoIdV2.timeout) { @@ -167,6 +189,21 @@ - (NSDictionary *)_buildParams { return params; } +- (NSString *)_buildParamsRandomHexString +{ + int keyLen = 32; + NSMutableString *kenStr = [[NSMutableString alloc]initWithCapacity:keyLen]; + for (int i = 0; i < keyLen; i++) { + [kenStr appendFormat:@"%x", arc4random() % 16]; + } + return [kenStr copy]; +} + +- (NSString *)_buildParamsEncryptHexString:(NSString *)originHexStr +{ + return [TXVodPlayer getEncryptedPlayKey:originHexStr]; +} + @end @implementation SuperPlayerVideoIdV2 diff --git a/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModelInternal.h b/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModelInternal.h index de95c3a0..887a4a70 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModelInternal.h +++ b/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerModelInternal.h @@ -52,6 +52,10 @@ NS_ASSUME_NONNULL_BEGIN /// DRM Type @property(nonatomic, assign) SPDrmType drmType; +@property NSString *_Nullable overlayKey; // HLS EXT-X-KEY 加密key + +@property NSString *_Nullable overlayIv; // HLS EXT-X-KEY 加密Iv + @end NS_ASSUME_NONNULL_END diff --git a/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerView.m b/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerView.m index 280e76fe..38fbd9d5 100644 --- a/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerView.m +++ b/Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerView.m @@ -426,6 +426,8 @@ - (void)configTXPlayer { config.headers = self.playerConfig.headers; + config.overlayIv = self.playerModel.overlayIv; + config.overlayKey = self.playerModel.overlayKey; [self.vodPlayer setConfig:config]; self.vodPlayer.enableHWAcceleration = self.playerConfig.hwAcceleration;