Commit c03450cedd5eec98dce10e6ad61086b871d6b349
1 parent
f55b0521
推流状态处理
Showing
10 changed files
with
194 additions
and
64 deletions
CNLivePlayerSDKTest/CNLivePlayerSDK.framework/CNLivePlayerSDK
No preview for this file type
CNLivePlayerSDKTest/CNLivePlayerSDK.framework/Info.plist
No preview for this file type
CNLivePlayerSDKTest/CNLivePlayerSDKTest.xcodeproj/project.pbxproj
| ... | ... | @@ -7,9 +7,6 @@ |
| 7 | 7 | objects = { |
| 8 | 8 | |
| 9 | 9 | /* Begin PBXBuildFile section */ |
| 10 | - 3236EF121DEEE1C800BF905D /* CNLivePlayerSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3236EF111DEEE1C800BF905D /* CNLivePlayerSDK.framework */; }; | |
| 11 | - 32ACF8B41DEEE1D4003247CD /* CNLivePlayerSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3236EF111DEEE1C800BF905D /* CNLivePlayerSDK.framework */; }; | |
| 12 | - 32ACF8B51DEEE1D4003247CD /* CNLivePlayerSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3236EF111DEEE1C800BF905D /* CNLivePlayerSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; | |
| 13 | 10 | 32B4C85A1D9B66A400925AF0 /* CNLiveViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32B4C8591D9B66A400925AF0 /* CNLiveViewController.m */; }; |
| 14 | 11 | 32B4C85D1D9B66E500925AF0 /* StreamerDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32B4C85C1D9B66E500925AF0 /* StreamerDetailViewController.m */; }; |
| 15 | 12 | 32E6CA2B1D5B0AF400B58EBC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 32E6CA2A1D5B0AF400B58EBC /* main.m */; }; |
| ... | ... | @@ -22,6 +19,9 @@ |
| 22 | 19 | 32E6CA921D5B2AF700B58EBC /* NormalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32E6CA881D5B2AF700B58EBC /* NormalViewController.m */; }; |
| 23 | 20 | 32E6CA931D5B2AF700B58EBC /* PlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32E6CA8A1D5B2AF700B58EBC /* PlayerViewController.m */; }; |
| 24 | 21 | 32E6CA951D5B2AF700B58EBC /* StreamerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32E6CA8F1D5B2AF700B58EBC /* StreamerViewController.m */; }; |
| 22 | + 8185C9EC1DF028E000AA83C7 /* CNLivePlayerSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8185C9EB1DF028E000AA83C7 /* CNLivePlayerSDK.framework */; }; | |
| 23 | + 8185C9ED1DF028E400AA83C7 /* CNLivePlayerSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8185C9EB1DF028E000AA83C7 /* CNLivePlayerSDK.framework */; }; | |
| 24 | + 8185C9EE1DF028E400AA83C7 /* CNLivePlayerSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8185C9EB1DF028E000AA83C7 /* CNLivePlayerSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; | |
| 25 | 25 | /* End PBXBuildFile section */ |
| 26 | 26 | |
| 27 | 27 | /* Begin PBXCopyFilesBuildPhase section */ |
| ... | ... | @@ -31,7 +31,7 @@ |
| 31 | 31 | dstPath = ""; |
| 32 | 32 | dstSubfolderSpec = 10; |
| 33 | 33 | files = ( |
| 34 | - 32ACF8B51DEEE1D4003247CD /* CNLivePlayerSDK.framework in Embed Frameworks */, | |
| 34 | + 8185C9EE1DF028E400AA83C7 /* CNLivePlayerSDK.framework in Embed Frameworks */, | |
| 35 | 35 | ); |
| 36 | 36 | name = "Embed Frameworks"; |
| 37 | 37 | runOnlyForDeploymentPostprocessing = 0; |
| ... | ... | @@ -39,7 +39,6 @@ |
| 39 | 39 | /* End PBXCopyFilesBuildPhase section */ |
| 40 | 40 | |
| 41 | 41 | /* Begin PBXFileReference section */ |
| 42 | - 3236EF111DEEE1C800BF905D /* CNLivePlayerSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CNLivePlayerSDK.framework; sourceTree = "<group>"; }; | |
| 43 | 42 | 32B4C8581D9B66A400925AF0 /* CNLiveViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLiveViewController.h; sourceTree = "<group>"; }; |
| 44 | 43 | 32B4C8591D9B66A400925AF0 /* CNLiveViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveViewController.m; sourceTree = "<group>"; }; |
| 45 | 44 | 32B4C85B1D9B66E500925AF0 /* StreamerDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamerDetailViewController.h; sourceTree = "<group>"; }; |
| ... | ... | @@ -62,6 +61,7 @@ |
| 62 | 61 | 32E6CA8A1D5B2AF700B58EBC /* PlayerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayerViewController.m; sourceTree = "<group>"; }; |
| 63 | 62 | 32E6CA8E1D5B2AF700B58EBC /* StreamerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamerViewController.h; sourceTree = "<group>"; }; |
| 64 | 63 | 32E6CA8F1D5B2AF700B58EBC /* StreamerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StreamerViewController.m; sourceTree = "<group>"; }; |
| 64 | + 8185C9EB1DF028E000AA83C7 /* CNLivePlayerSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CNLivePlayerSDK.framework; sourceTree = "<group>"; }; | |
| 65 | 65 | /* End PBXFileReference section */ |
| 66 | 66 | |
| 67 | 67 | /* Begin PBXFrameworksBuildPhase section */ |
| ... | ... | @@ -69,8 +69,8 @@ |
| 69 | 69 | isa = PBXFrameworksBuildPhase; |
| 70 | 70 | buildActionMask = 2147483647; |
| 71 | 71 | files = ( |
| 72 | - 3236EF121DEEE1C800BF905D /* CNLivePlayerSDK.framework in Frameworks */, | |
| 73 | - 32ACF8B41DEEE1D4003247CD /* CNLivePlayerSDK.framework in Frameworks */, | |
| 72 | + 8185C9EC1DF028E000AA83C7 /* CNLivePlayerSDK.framework in Frameworks */, | |
| 73 | + 8185C9ED1DF028E400AA83C7 /* CNLivePlayerSDK.framework in Frameworks */, | |
| 74 | 74 | ); |
| 75 | 75 | runOnlyForDeploymentPostprocessing = 0; |
| 76 | 76 | }; |
| ... | ... | @@ -80,7 +80,7 @@ |
| 80 | 80 | 32E6CA1D1D5B0AF400B58EBC = { |
| 81 | 81 | isa = PBXGroup; |
| 82 | 82 | children = ( |
| 83 | - 3236EF111DEEE1C800BF905D /* CNLivePlayerSDK.framework */, | |
| 83 | + 8185C9EB1DF028E000AA83C7 /* CNLivePlayerSDK.framework */, | |
| 84 | 84 | 32E6CA281D5B0AF400B58EBC /* CNLivePlayerSDKTest */, |
| 85 | 85 | 32E6CA271D5B0AF400B58EBC /* Products */, |
| 86 | 86 | ); | ... | ... |
CNLivePlayerSDKTest/CNLivePlayerSDKTest.xcodeproj/project.xcworkspace/xcuserdata/iOS.xcuserdatad/UserInterfaceState.xcuserstate
0 → 100644
No preview for this file type
CNLivePlayerSDKTest/CNLivePlayerSDKTest.xcodeproj/xcuserdata/iOS.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
0 → 100644
CNLivePlayerSDKTest/CNLivePlayerSDKTest.xcodeproj/xcuserdata/iOS.xcuserdatad/xcschemes/CNLivePlayerSDKTest.xcscheme
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<Scheme | |
| 3 | + LastUpgradeVersion = "0810" | |
| 4 | + version = "1.3"> | |
| 5 | + <BuildAction | |
| 6 | + parallelizeBuildables = "YES" | |
| 7 | + buildImplicitDependencies = "YES"> | |
| 8 | + <BuildActionEntries> | |
| 9 | + <BuildActionEntry | |
| 10 | + buildForTesting = "YES" | |
| 11 | + buildForRunning = "YES" | |
| 12 | + buildForProfiling = "YES" | |
| 13 | + buildForArchiving = "YES" | |
| 14 | + buildForAnalyzing = "YES"> | |
| 15 | + <BuildableReference | |
| 16 | + BuildableIdentifier = "primary" | |
| 17 | + BlueprintIdentifier = "32E6CA251D5B0AF400B58EBC" | |
| 18 | + BuildableName = "CNLivePlayerSDKTest.app" | |
| 19 | + BlueprintName = "CNLivePlayerSDKTest" | |
| 20 | + ReferencedContainer = "container:CNLivePlayerSDKTest.xcodeproj"> | |
| 21 | + </BuildableReference> | |
| 22 | + </BuildActionEntry> | |
| 23 | + </BuildActionEntries> | |
| 24 | + </BuildAction> | |
| 25 | + <TestAction | |
| 26 | + buildConfiguration = "Debug" | |
| 27 | + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | |
| 28 | + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | |
| 29 | + shouldUseLaunchSchemeArgsEnv = "YES"> | |
| 30 | + <Testables> | |
| 31 | + </Testables> | |
| 32 | + <MacroExpansion> | |
| 33 | + <BuildableReference | |
| 34 | + BuildableIdentifier = "primary" | |
| 35 | + BlueprintIdentifier = "32E6CA251D5B0AF400B58EBC" | |
| 36 | + BuildableName = "CNLivePlayerSDKTest.app" | |
| 37 | + BlueprintName = "CNLivePlayerSDKTest" | |
| 38 | + ReferencedContainer = "container:CNLivePlayerSDKTest.xcodeproj"> | |
| 39 | + </BuildableReference> | |
| 40 | + </MacroExpansion> | |
| 41 | + <AdditionalOptions> | |
| 42 | + </AdditionalOptions> | |
| 43 | + </TestAction> | |
| 44 | + <LaunchAction | |
| 45 | + buildConfiguration = "Debug" | |
| 46 | + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | |
| 47 | + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | |
| 48 | + launchStyle = "0" | |
| 49 | + useCustomWorkingDirectory = "NO" | |
| 50 | + ignoresPersistentStateOnLaunch = "NO" | |
| 51 | + debugDocumentVersioning = "YES" | |
| 52 | + debugServiceExtension = "internal" | |
| 53 | + allowLocationSimulation = "YES"> | |
| 54 | + <BuildableProductRunnable | |
| 55 | + runnableDebuggingMode = "0"> | |
| 56 | + <BuildableReference | |
| 57 | + BuildableIdentifier = "primary" | |
| 58 | + BlueprintIdentifier = "32E6CA251D5B0AF400B58EBC" | |
| 59 | + BuildableName = "CNLivePlayerSDKTest.app" | |
| 60 | + BlueprintName = "CNLivePlayerSDKTest" | |
| 61 | + ReferencedContainer = "container:CNLivePlayerSDKTest.xcodeproj"> | |
| 62 | + </BuildableReference> | |
| 63 | + </BuildableProductRunnable> | |
| 64 | + <AdditionalOptions> | |
| 65 | + </AdditionalOptions> | |
| 66 | + </LaunchAction> | |
| 67 | + <ProfileAction | |
| 68 | + buildConfiguration = "Release" | |
| 69 | + shouldUseLaunchSchemeArgsEnv = "YES" | |
| 70 | + savedToolIdentifier = "" | |
| 71 | + useCustomWorkingDirectory = "NO" | |
| 72 | + debugDocumentVersioning = "YES"> | |
| 73 | + <BuildableProductRunnable | |
| 74 | + runnableDebuggingMode = "0"> | |
| 75 | + <BuildableReference | |
| 76 | + BuildableIdentifier = "primary" | |
| 77 | + BlueprintIdentifier = "32E6CA251D5B0AF400B58EBC" | |
| 78 | + BuildableName = "CNLivePlayerSDKTest.app" | |
| 79 | + BlueprintName = "CNLivePlayerSDKTest" | |
| 80 | + ReferencedContainer = "container:CNLivePlayerSDKTest.xcodeproj"> | |
| 81 | + </BuildableReference> | |
| 82 | + </BuildableProductRunnable> | |
| 83 | + </ProfileAction> | |
| 84 | + <AnalyzeAction | |
| 85 | + buildConfiguration = "Debug"> | |
| 86 | + </AnalyzeAction> | |
| 87 | + <ArchiveAction | |
| 88 | + buildConfiguration = "Release" | |
| 89 | + revealArchiveInOrganizer = "YES"> | |
| 90 | + </ArchiveAction> | |
| 91 | +</Scheme> | ... | ... |
CNLivePlayerSDKTest/CNLivePlayerSDKTest.xcodeproj/xcuserdata/iOS.xcuserdatad/xcschemes/xcschememanagement.plist
0 → 100644
| 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>SchemeUserState</key> | |
| 6 | + <dict> | |
| 7 | + <key>CNLivePlayerSDKTest.xcscheme</key> | |
| 8 | + <dict> | |
| 9 | + <key>orderHint</key> | |
| 10 | + <integer>0</integer> | |
| 11 | + </dict> | |
| 12 | + </dict> | |
| 13 | + <key>SuppressBuildableAutocreation</key> | |
| 14 | + <dict> | |
| 15 | + <key>32E6CA251D5B0AF400B58EBC</key> | |
| 16 | + <dict> | |
| 17 | + <key>primary</key> | |
| 18 | + <true/> | |
| 19 | + </dict> | |
| 20 | + </dict> | |
| 21 | +</dict> | |
| 22 | +</plist> | ... | ... |
CNLivePlayerSDKTest/CNLivePlayerSDKTest/Streamer/StreamerDetailViewController.m
| ... | ... | @@ -8,14 +8,21 @@ |
| 8 | 8 | |
| 9 | 9 | #import "StreamerDetailViewController.h" |
| 10 | 10 | #import <CNLivePlayerSDK/CNLiveGPUStreamerKit.h> |
| 11 | +#import "CommonCrypto/CommonDigest.h" | |
| 11 | 12 | |
| 12 | 13 | #define Width [UIScreen mainScreen].bounds.size.width |
| 13 | 14 | #define Height [UIScreen mainScreen].bounds.size.height |
| 14 | 15 | |
| 16 | +#define kAPPID @"60_irg1rhs308" | |
| 17 | +#define kAPPKEY @"4e7a37b27a717a9e9b0a7aea4620ee55ea61fbf923bf46" | |
| 18 | + | |
| 19 | + | |
| 15 | 20 | @interface StreamerDetailViewController ()<UIGestureRecognizerDelegate> |
| 16 | 21 | { |
| 17 | 22 | UILabel *_stateLab; |
| 18 | 23 | UIButton *_startLiveBtn; |
| 24 | + | |
| 25 | + NSString *_activityId; //用于查询活动状态 | |
| 19 | 26 | } |
| 20 | 27 | |
| 21 | 28 | @property (nonatomic,strong) UIView *captureView; |
| ... | ... | @@ -34,17 +41,16 @@ |
| 34 | 41 | |
| 35 | 42 | if (_isAuthLive) { |
| 36 | 43 | |
| 37 | - //用时间戳作为活动id 确保唯一性 | |
| 38 | - NSDate *date = [NSDate date]; | |
| 39 | - NSInteger time = [date timeIntervalSince1970]; | |
| 40 | - NSString *activityId = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 44 | + NSString *activityId = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9]; | |
| 45 | + | |
| 46 | + _activityId = activityId; | |
| 41 | 47 | |
| 42 | - _kitCN = [[CNLiveGPUStreamerKit alloc] initWithDefaultConfigWithAppId:@"60_irg1rhs308" appKey:@"4e7a37b27a717a9e9b0a7aea4620ee55ea61fbf923bf46" activityId:activityId channelId:@"iOStest" isHorizontalScreen:@"0"]; | |
| 48 | + _kitCN = [[CNLiveGPUStreamerKit alloc] initWithDefaultConfigWithAppId:kAPPID appKey:kAPPKEY activityId:activityId channelId:@"iosTest" isHorizontalScreen:@"0"]; | |
| 49 | + | |
| 50 | + // _kitCN.activityName = @"iOS test"; | |
| 51 | + // _kitCN.coverImgUrl = @"djfiwooa"; | |
| 43 | 52 | |
| 44 | - //推流配置 | |
| 45 | 53 | [self setStreamerCfg]; |
| 46 | - [_kitCN startPreview:self.captureView]; | |
| 47 | - //推流状态通知 | |
| 48 | 54 | [self addObservers]; |
| 49 | 55 | |
| 50 | 56 | }else{ |
| ... | ... | @@ -54,12 +60,14 @@ |
| 54 | 60 | |
| 55 | 61 | [self setStreamerCfg]; |
| 56 | 62 | [self addObservers]; |
| 57 | - | |
| 63 | + | |
| 58 | 64 | } |
| 59 | 65 | |
| 60 | 66 | _startLiveBtn = [self addButton:@"开始直播" frame:CGRectMake(100, 40, 80, 40) action:@selector(startCapture:)]; |
| 67 | + [_startLiveBtn setTitle:@"开始直播" forState:UIControlStateNormal]; | |
| 68 | + [_startLiveBtn setTitle:@"停止直播" forState:UIControlStateSelected]; | |
| 61 | 69 | |
| 62 | - [self addButton:@"开启预览" frame:CGRectMake(10, 40, 80, 40) action:@selector(startPreview:)]; | |
| 70 | + [self addButton:@"关闭预览" frame:CGRectMake(10, 40, 80, 40) action:@selector(startPreview:)]; | |
| 63 | 71 | |
| 64 | 72 | [self addButton:@"退出" frame:CGRectMake(190, 40, 80, 40) action:@selector(quit)]; |
| 65 | 73 | |
| ... | ... | @@ -81,6 +89,20 @@ |
| 81 | 89 | |
| 82 | 90 | } |
| 83 | 91 | |
| 92 | +- (void)addObservers | |
| 93 | +{ | |
| 94 | + [[NSNotificationCenter defaultCenter] addObserver:self | |
| 95 | + selector:@selector(captureStateChange) | |
| 96 | + name:CNLiveCaptureStateDidChangeNotification | |
| 97 | + object:nil]; | |
| 98 | + | |
| 99 | + [[NSNotificationCenter defaultCenter] addObserver:self | |
| 100 | + selector:@selector(streamStateChange) | |
| 101 | + name:CNLiveStreamStateDidChangeNotification | |
| 102 | + object:nil]; | |
| 103 | + | |
| 104 | +} | |
| 105 | + | |
| 84 | 106 | - (UIButton *)addButton:(NSString*)title |
| 85 | 107 | frame:(CGRect)frame |
| 86 | 108 | action:(SEL)action { |
| ... | ... | @@ -91,6 +113,11 @@ |
| 91 | 113 | button.backgroundColor = [UIColor lightGrayColor]; |
| 92 | 114 | [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; |
| 93 | 115 | button.titleLabel.font = [UIFont systemFontOfSize:15]; |
| 116 | + [button setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal]; | |
| 117 | + button.layer.cornerRadius = 10; | |
| 118 | + button.layer.masksToBounds = YES; | |
| 119 | + button.layer.borderColor = [UIColor blackColor].CGColor; | |
| 120 | + button.layer.borderWidth = 1; | |
| 94 | 121 | [self.captureView addSubview:button]; |
| 95 | 122 | return button; |
| 96 | 123 | } |
| ... | ... | @@ -107,6 +134,7 @@ |
| 107 | 134 | _kitCN.enAutoApplyEstimateBW = YES; |
| 108 | 135 | _kitCN.isOpenImageFilter = YES; |
| 109 | 136 | [_kitCN setVideoOrientationBy:UIInterfaceOrientationPortrait]; |
| 137 | + [_kitCN startPreview:self.captureView]; | |
| 110 | 138 | } |
| 111 | 139 | |
| 112 | 140 | #pragma mark - Action |
| ... | ... | @@ -115,16 +143,17 @@ |
| 115 | 143 | { |
| 116 | 144 | button.selected = !button.selected; |
| 117 | 145 | if (button.selected) { |
| 118 | - [_kitCN startPreview:self.captureView]; | |
| 119 | - [button setTitle:@"关闭预览" forState:UIControlStateNormal]; | |
| 120 | - }else{ | |
| 146 | + _startLiveBtn.enabled = NO; | |
| 121 | 147 | [button setTitle:@"开启预览" forState:UIControlStateNormal]; |
| 122 | 148 | if (_kitCN.streamState == CNLiveStreamStateConnected) { |
| 123 | 149 | [_kitCN stopStream]; |
| 124 | - [_startLiveBtn setTitle:@"开始直播" forState:UIControlStateNormal]; | |
| 125 | 150 | _startLiveBtn.selected = NO; |
| 126 | 151 | } |
| 127 | 152 | [_kitCN stopPreview]; |
| 153 | + }else{ | |
| 154 | + [_kitCN startPreview:self.captureView]; | |
| 155 | + [button setTitle:@"关闭预览" forState:UIControlStateNormal]; | |
| 156 | + _startLiveBtn.enabled = YES; | |
| 128 | 157 | } |
| 129 | 158 | } |
| 130 | 159 | |
| ... | ... | @@ -133,27 +162,21 @@ |
| 133 | 162 | button.selected = !button.selected; |
| 134 | 163 | |
| 135 | 164 | if (button.selected) { |
| 136 | - [button setTitle:@"停止直播" forState:UIControlStateNormal]; | |
| 137 | 165 | if (_isAuthLive) { |
| 138 | 166 | |
| 139 | -#warning 活动附加信息必须在开始推流前设置 | |
| 140 | - _kitCN.activityName = @"iOStest"; | |
| 141 | - | |
| 142 | 167 | [_kitCN startStream:^{ |
| 143 | 168 | NSLog(@"开启推流成功 ------- success"); |
| 144 | 169 | } failure:^(NSDictionary *errorDic) { |
| 145 | 170 | [self toast:errorDic[@"errorMessage"]]; |
| 171 | + _startLiveBtn.selected = NO; | |
| 146 | 172 | }]; |
| 147 | - | |
| 173 | + | |
| 148 | 174 | }else{ |
| 149 | 175 | [_kitCN startStream:_hostURL]; |
| 150 | 176 | } |
| 151 | 177 | }else{ |
| 152 | 178 | _stateLab.text = nil; |
| 153 | - | |
| 154 | 179 | [_kitCN stopStream]; |
| 155 | - | |
| 156 | - [button setTitle:@"开始直播" forState:UIControlStateNormal]; | |
| 157 | 180 | } |
| 158 | 181 | } |
| 159 | 182 | |
| ... | ... | @@ -165,19 +188,19 @@ |
| 165 | 188 | |
| 166 | 189 | - (void)changeCamera:(UIButton *)button |
| 167 | 190 | { |
| 168 | -// button.selected = !button.selected; | |
| 169 | -// if (button.selected) { | |
| 170 | -// _kitCN.cameraPosition = AVCaptureDevicePositionBack; | |
| 171 | -// }else{ | |
| 172 | -// _kitCN.cameraPosition = AVCaptureDevicePositionFront; | |
| 173 | -// } | |
| 191 | + // button.selected = !button.selected; | |
| 192 | + // if (button.selected) { | |
| 193 | + // _kitCN.cameraPosition = AVCaptureDevicePositionBack; | |
| 194 | + // }else{ | |
| 195 | + // _kitCN.cameraPosition = AVCaptureDevicePositionFront; | |
| 196 | + // } | |
| 174 | 197 | [_kitCN switchCamera]; |
| 175 | 198 | } |
| 176 | 199 | |
| 177 | 200 | - (void)openFlash |
| 178 | 201 | { |
| 179 | 202 | [_kitCN toggleTorch]; |
| 180 | -// [_kitCN setTorchMode:AVCaptureTorchModeOn]; | |
| 203 | + // [_kitCN setTorchMode:AVCaptureTorchModeOn]; | |
| 181 | 204 | } |
| 182 | 205 | |
| 183 | 206 | - (void)quit |
| ... | ... | @@ -192,20 +215,8 @@ |
| 192 | 215 | [self dismissViewControllerAnimated:YES completion:NULL]; |
| 193 | 216 | } |
| 194 | 217 | |
| 195 | -- (void)addObservers | |
| 196 | -{ | |
| 197 | - [[NSNotificationCenter defaultCenter] addObserver:self | |
| 198 | - selector:@selector(captureStateChange) | |
| 199 | - name:CNLiveCaptureStateDidChangeNotification | |
| 200 | - object:nil]; | |
| 201 | - | |
| 202 | - [[NSNotificationCenter defaultCenter] addObserver:self | |
| 203 | - selector:@selector(streamStateChange) | |
| 204 | - name:CNLiveStreamStateDidChangeNotification | |
| 205 | - object:nil]; | |
| 206 | -} | |
| 207 | - | |
| 208 | 218 | #pragma mark - notification |
| 219 | + | |
| 209 | 220 | - (void)captureStateChange |
| 210 | 221 | { |
| 211 | 222 | |
| ... | ... | @@ -295,7 +306,8 @@ |
| 295 | 306 | } |
| 296 | 307 | } |
| 297 | 308 | |
| 298 | -- (void) onStreamError { | |
| 309 | +- (void)onStreamError { | |
| 310 | + | |
| 299 | 311 | CNLiveStreamErrorCode err = _kitCN.streamErrorCode; |
| 300 | 312 | |
| 301 | 313 | if ( CNLiveStreamErrorCode_CNLiveAUTHFAILED == err ) { |
| ... | ... | @@ -311,14 +323,13 @@ |
| 311 | 323 | _stateLab.text = @"Connection break"; |
| 312 | 324 | } |
| 313 | 325 | else if ( CNLiveStreamErrorCode_ABNORMAL == err) { |
| 314 | - _stateLab.text = @"Connection break"; | |
| 315 | - } | |
| 316 | - else { | |
| 326 | + _stateLab.text = @"CNLiveStreamErrorCode_ABNORMAL"; | |
| 317 | 327 | [self toast:@"推流异常中断~~"]; |
| 318 | - NSLog(@"---------推流异常中断~~"); | |
| 319 | - [_startLiveBtn setTitle:@"开始直播" forState:UIControlStateNormal]; | |
| 320 | 328 | _startLiveBtn.selected = NO; |
| 321 | 329 | } |
| 330 | + else { | |
| 331 | + | |
| 332 | + } | |
| 322 | 333 | NSLog(@"onErr: %lu [%@]", (unsigned long) err, _stateLab.text); |
| 323 | 334 | // 断网重连 |
| 324 | 335 | if ( CNLiveStreamErrorCode_CONNECT_BREAK == err) { |
| ... | ... | @@ -332,6 +343,7 @@ |
| 332 | 343 | NSLog(@"开启推流成功 ------- success"); |
| 333 | 344 | } failure:^(NSDictionary *errorDic) { |
| 334 | 345 | [self toast:errorDic[@"errorMessage"]]; |
| 346 | + _startLiveBtn.selected = NO; | |
| 335 | 347 | }]; |
| 336 | 348 | |
| 337 | 349 | }else{ |
| ... | ... | @@ -404,13 +416,13 @@ |
| 404 | 416 | } |
| 405 | 417 | |
| 406 | 418 | /* |
| 407 | -#pragma mark - Navigation | |
| 408 | - | |
| 409 | -// In a storyboard-based application, you will often want to do a little preparation before navigation | |
| 410 | -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
| 411 | - // Get the new view controller using [segue destinationViewController]. | |
| 412 | - // Pass the selected object to the new view controller. | |
| 413 | -} | |
| 414 | -*/ | |
| 419 | + #pragma mark - Navigation | |
| 420 | + | |
| 421 | + // In a storyboard-based application, you will often want to do a little preparation before navigation | |
| 422 | + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
| 423 | + // Get the new view controller using [segue destinationViewController]. | |
| 424 | + // Pass the selected object to the new view controller. | |
| 425 | + } | |
| 426 | + */ | |
| 415 | 427 | |
| 416 | 428 | @end | ... | ... |
推流SDK文档.pdf
No preview for this file type
播放SDK文档.pdf
No preview for this file type