iOS | Android | Mac OS | Windows | Electron | Chrome 浏览器 |
✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
TRTCVideoEncParam
即可。该参数可以设置为 nil,此时 SDK 会沿用开始屏幕分享之前的编码参数。参数项 | 参数名称 | 常规推荐值 | 文字教学场景 |
分辨率 | videoResolution | 1280 × 720 | 1920 × 1080 |
帧率 | videoFps | 10 FPS | 8 FPS |
最高码率 | videoBitrate | 1600 kbps | 2000 kbps |
分辨率自适应 | enableAdjustRes | NO | NO |
TXLiteAVSDK_ReplayKitExt.framework
。Target名.entitlements
的文件,如下图所示,选中该文件并单击 + 号填写上述步骤中的 App Group 即可。#import "SampleHandler.h"@import TXLiteAVSDK_ReplayKitExt;#define APPGROUP @"group.com.tencent.liteav.RPLiveStreamShare"@interface SampleHandler() <TXReplayKitExtDelegate>@end@implementation SampleHandler// 注意:此处的 APPGROUP 需要改成上文中的创建的 App Group Identifier。- (void)broadcastStartedWithSetupInfo:(NSDictionary<NSString *,NSObject *> *)setupInfo {[[TXReplayKitExt sharedInstance] setupWithAppGroup:APPGROUP delegate:self];}- (void)broadcastPaused {// User has requested to pause the broadcast. Samples will stop being delivered.}- (void)broadcastResumed {// User has requested to resume the broadcast. Samples delivery will resume.}- (void)broadcastFinished {[[TXReplayKitExt sharedInstance] finishBroadcast];// User has requested to finish the broadcast.}#pragma mark - TXReplayKitExtDelegate- (void)broadcastFinished:(TXReplayKitExt *)broadcast reason:(TXReplayKitExtReason)reason{NSString *tip = @"";switch (reason) {case TXReplayKitExtReasonRequestedByMain:tip = @"屏幕共享已结束";break;case TXReplayKitExtReasonDisconnected:tip = @"应用断开";break;case TXReplayKitExtReasonVersionMismatch:tip = @"集成错误(SDK 版本号不相符合)";break;}NSError *error = [NSError errorWithDomain:NSStringFromClass(self.class)code:0userInfo:@{NSLocalizedFailureReasonErrorKey:tip}];[self finishBroadcastWithError:error];}- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType {switch (sampleBufferType) {case RPSampleBufferTypeVideo:[[TXReplayKitExt sharedInstance] sendVideoSampleBuffer:sampleBuffer];break;case RPSampleBufferTypeAudioApp:// Handle audio sample buffer for app audiobreak;case RPSampleBufferTypeAudioMic:// Handle audio sample buffer for mic audiobreak;default:break;}}@end
// 开始屏幕分享,需要将 APPGROUP 替换为上述步骤中创建的 App Group Identifier。- (void)startScreenCapture {TRTCVideoEncParam *videoEncConfig = [[TRTCVideoEncParam alloc] init];videoEncConfig.videoResolution = TRTCVideoResolution_1280_720;videoEncConfig.videoFps = 10;videoEncConfig.videoBitrate = 2000;//需要将 APPGROUP 替换为上述步骤中创建的 App Group Identifier:[[TRTCCloud sharedInstance] startScreenCaptureByReplaykit:videoEncConfigappGroup:APPGROUP];}// 停止屏幕分享- (void)stopScreenCapture {[[TRTCCloud sharedInstance] stopScreenCapture];}// 屏幕分享的启动事件通知,可以通过 TRTCCloudDelegate 进行接收- (void)onScreenCaptureStarted {[self showTip:@"屏幕分享开始"];}
TRTCBroadcastExtensionLauncher
中的 launch
函数,就可以唤起屏幕分享功能了。// 自定义按钮响应方法- (IBAction)onScreenButtonTapped:(id)sender {[TRTCBroadcastExtensionLauncher launch];}
RPSystemBroadcastPickerView
可以从应用中弹出启动器供用户确认启动屏幕分享,到目前为止, RPSystemBroadcastPickerView
尚不支持自定义界面,也没有官方的唤起方法。RPSystemBroadcastPickerView
的子 View 寻找 UIButton 并触发了其点击事件。
本页内容是否解决了您的问题?