
<activityandroid:name="com.tencent.rtmp.video.TXScreenCapture$TXScreenCaptureAssistantActivity"android:theme="@android:style/Theme.Translucent"/>
encParams ,您可以指定屏幕分享的编码质量。如果您指定 encParams 为 null,SDK 会自动使用之前设定的编码参数,我们推荐的参数设定如下:参数项 | 参数名称 | 常规推荐值 | 文字教学场景 |
分辨率 | videoResolution | 1280 × 720 | 1920 × 1080 |
帧率 | videoFps | 10 FPS | 8 FPS |
最高码率 | videoBitrate | 1600 kbps | 2000 kbps |
分辨率自适应 | enableAdjustRes | NO | NO |
TRTCVideoEncParam。TRTCVideoEncParam 参数可以设置为 null,此时 SDK 会沿用开始屏幕分享之前的编码参数。参数项 | 参数名称 | 常规推荐值 | 文字教学场景 |
分辨率 | videoResolution | 1280 × 720 | 1920 × 1080 |
帧率 | videoFps | 10 FPS | 8 FPS |
最高码率 | videoBitrate | 1600 kbps | 2000 kbps |
分辨率自适应 | enableAdjustRes | NO | NO |
pubspec.yaml 文件引入 replay_kit_launcher 插件 ,实现类似TRTC Demo Screen中点击一个按钮即可唤起屏幕分享的效果(可选)。# 引入 trtc sdk和replay_kit_launcherdependencies:tencent_rtc_sdk: ^12.5.4replay_kit_launcher: any



Target.entitlements 的文件,如下图所示,选中该文件并单击 + 号填写上述步骤中的 App Group 即可。
import ReplayKitimport TXLiteAVSDK_ReplayKitExtlet APPGROUP = "group.com.tencent.comm.trtc.demo"class SampleHandler: RPBroadcastSampleHandler, TXReplayKitExtDelegate {let recordScreenKey = Notification.Name.init("TRTCRecordScreenKey")override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {// User has requested to start the broadcast. Setup info from the UI extension can be supplied but optional.TXReplayKitExt.sharedInstance().setup(withAppGroup: APPGROUP, delegate: self)}override func broadcastPaused() {// User has requested to pause the broadcast. Samples will stop being delivered.}override func broadcastResumed() {// User has requested to resume the broadcast. Samples delivery will resume.}override func broadcastFinished() {// User has requested to finish the broadcast.TXReplayKitExt.sharedInstance() .finishBroadcast()}func broadcastFinished(_ broadcast: TXReplayKitExt, reason: TXReplayKitExtReason) {var tip = ""switch reason {case TXReplayKitExtReason.requestedByMain:tip = "屏幕共享已结束"breakcase TXReplayKitExtReason.disconnected:tip = "应用断开"breakcase TXReplayKitExtReason.versionMismatch:tip = "集成错误(SDK 版本号不相符合)"breakdefault:break}let error = NSError(domain: NSStringFromClass(self.classForCoder), code: 0, userInfo: [NSLocalizedFailureReasonErrorKey:tip])finishBroadcastWithError(error)}override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {switch sampleBufferType {case RPSampleBufferType.video:// Handle video sample bufferTXReplayKitExt.sharedInstance() .sendVideoSampleBuffer(sampleBuffer)breakcase RPSampleBufferType.audioApp:// Handle audio sample buffer for app audiobreakcase RPSampleBufferType.audioMic:// Handle audio sample buffer for mic audiobreak@unknown default:// Handle other sample buffer typesfatalError("Unknown type of sample buffer")}}}

_trtcCloud.startScreenCaptureByReplaykit(TRTCVideoStreamType.sub,TRTCVideoEncParam(videoFps: 15,videoResolution: TRTCVideoResolution.res_640_360,videoBitrate: 1600,minVideoBitrate: 0,enableAdjustRes: false,videoResolutionMode: TRTCVideoResolutionMode.landscape,), "your app group");ReplayKitLauncher.launchReplayKitBroadcast("screen capture");
startScreenCapture接口时,通过将TRTCVideoStreamType参数指定为sub 来启用该模式。startScreenCapture接口时,通过将TRTCVideoStreamType参数指定为 big来启用该模式。
清晰度级别 | 分辨率 | 帧率 | 码率 |
超高清(HD+) | 1920 × 1080 | 10 | 800kbps |
高清(HD) | 1280 × 720 | 10 | 600kbps |
标清(SD) | 960 × 720 | 10 | 400kbps |
encParams 为 null,SDK 会自动使用之前设定的编码参数。文档反馈