<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
和 参数appGroup
设置为''
。TRTCVideoEncParam
参数可以设置为 null,此时 SDK 会沿用开始屏幕分享之前的编码参数。参数项 | 参数名称 | 常规推荐值 | 文字教学场景 |
分辨率 | videoResolution | 1280 × 720 | 1920 × 1080 |
帧率 | videoFps | 10 FPS | 8 FPS |
最高码率 | videoBitrate | 1600 kbps | 2000 kbps |
分辨率自适应 | enableAdjustRes | NO | NO |
├── Broadcast.Upload //录屏进程 Broadcast Upload Extension 代码详见步骤2│ ├── Broadcast.Upload.entitlements //用于设置进程间通信的 AppGroup 信息│ ├── Broadcast.UploadDebug.entitlements //用于设置进程间通信的 AppGroup 信息(debug环境)│ ├── Info.plist│ └── SampleHandler.swift // 用于接收来自系统的录屏数据├── Resource // 资源文件├── Runner // TRTC 精简化 Demo├── TXLiteAVSDK_ReplayKitExt.framework //TXLiteAVSDK_ReplayKitExt SDK
TXLiteAVSDK_ReplayKitExt.framework
。pubspec.yaml
文件引入 replay_kit_launcher
插件 ,实现类似TRTC Demo Screen中点击一个按钮即可唤起屏幕分享的效果(可选)。# 引入 trtc sdk和replay_kit_launcherdependencies:tencent_trtc_cloud: ^0.2.1replay_kit_launcher: ^0.2.0+1
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")}}}
// 开始屏幕分享,需要将 APPGROUP 替换为上述步骤中创建的 App GrouptrtcCloud.startScreenCapture(TRTCVideoEncParam(videoFps: 10,videoResolution: TRTCCloudDef.TRTC_VIDEO_RESOLUTION_1280_720,videoBitrate: 1600,videoResolutionMode: TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAIT,),iosAppGroup,);// 停止屏幕分享await trtcCloud.stopScreenCapture();// 屏幕分享的启动事件通知,可以通过 TRTCCloudListener 进行接收onRtcListener(type, param){if (type == TRTCCloudListener.onScreenCaptureStarted) {//屏幕分享开始}}
replay_kit_launcher
插件加入到您的工程中。ReplayKitLauncher.launchReplayKitBroadcast(iosExtensionName);
函数,就可以唤起屏幕分享功能了。// 自定义按钮响应方法onShareClick() async {if (Platform.isAndroid) {if (await SystemAlertWindow.requestPermissions) {MeetingTool.showOverlayWindow();}} else {//屏幕分享功能只能在真机测试ReplayKitLauncher.launchReplayKitBroadcast(iosExtensionName);}}
startScreenCapture
接口时,通过将TRTCVideoStreamType
参数指定为TRTCVideoStreamTypeSub
来启用该模式。startScreenCapture
接口时,通过将TRTCVideoStreamType
参数指定为 TRTCVideoStreamTypeBig
来启用该模式。清晰度级别 | 分辨率 | 帧率 | 码率 |
超高清(HD+) | 1920 × 1080 | 10 | 800kbps |
高清(HD) | 1280 × 720 | 10 | 600kbps |
标清(SD) | 960 × 720 | 10 | 400kbps |
encParams
为 null,SDK 会自动使用之前设定的编码参数。
本页内容是否解决了您的问题?