TRTCCloud
. However, to ensure the stability and video quality of screen sharing, you need to do the following.<activityandroid:name="com.tencent.rtmp.video.TXScreenCapture$TXScreenCaptureAssistantActivity"android:theme="@android:style/Theme.Translucent"/>
encParams
in startScreenCapture(), you can specify the encoding quality of screen sharing. If encParams
is set to null
, the SDK will use the encoding parameters set previously. We recommend the following settings:Item | Parameter | Recommended Value for Regular Scenarios | Recommended Value for Text-based Teaching |
Resolution | videoResolution | 1280 × 720 | 1920 × 1080 |
Frame rate | videoFps | 10 fps | 8 fps |
Highest bitrate | videoBitrate | 1600 Kbps | 2000 Kbps |
Resolution adaption | enableAdjustRes | NO | NO |
videoBitrate
) refers to the highest output bitrate when a shared screen changes dramatically. If the shared content does not change a lot, the actual encoding bitrate will be lower.TRTCVideoEncParam
, and setting the appGroup
parameter to ''
. If TRTCVideoEncParam
is set to null
, the SDK will use the encoding parameters set previously.Item | Parameter | Recommended Value for Regular Scenarios | Recommended Value for Text-based Teaching |
Resolution | videoResolution | 1280 × 720 | 1920 × 1080 |
Frame rate | videoFps | 10 fps | 8 fps |
Highest bitrate | videoBitrate | 1600 Kbps | 2000 Kbps |
Resolution adaption | enableAdjustRes | NO | NO |
videoBitrate
) refers to the highest output bitrate when a shared screen changes dramatically. If the shared content does not change a lot, the actual encoding bitrate will be lower.├── Broadcast.Upload // Code for the screen recording process Broadcast Upload Extension. For details, see step 2 below.│ ├── Broadcast.Upload.entitlements // Code for configuring an App Group to enable communication between processes│ ├── Broadcast.UploadDebug.entitlements // Code for configuring an App Group to enable communication between processes (debug environment)│ ├── Info.plist│ └── SampleHandler.swift // Code for receiving screen recording data from the system├── Resource // Resource file├── Runner // A simple TRTC demo├── TXLiteAVSDK_ReplayKitExt.framework //TXLiteAVSDK_ReplayKitExt SDK
TXLiteAVSDK_ReplayKitExt.framework
from the SDK package, which is tailored for the extension module.pubspec.yaml
file and import the replay_kit_launcher
plugin to make it possible to start screen sharing by tapping a button (optional), as in TRTC Demo Screen.# Import the TRTC SDK and `replay_kit_launcher`dependencies:tencent_trtc_cloud: ^0.2.1replay_kit_launcher: ^0.2.0+1
null
in the API), you can still enable the screen sharing feature, but its stability will be compromised. Therefore, to ensure the stability of screen sharing, we suggest that you configure an App Group as described in this document.AppGroup
value passed in to the API. After this, click Continue.TXLiteAVSDK_ReplayKitExt.framework
in the SDK package into the project and select the target created.target name.entitlements
will appear in the file list as shown below. Select it, click "+", and enter the App Group
created earlier.SampleHandler.swift
file. Replace the file content with the following code. You need to change APPGROUP
in the code to the App Group Identifier created earlier.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 = "Screen sharing ended"breakcase TXReplayKitExtReason.disconnected:tip = "App was disconnected"breakcase TXReplayKitExtReason.versionMismatch:tip = "Integration error (SDK version mismatch)"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
; if not, call stopLocalPreview to disable it.AppGroup
set in step 1 to put the SDK on standby.// Start screen sharing. You need to replace `APPGROUP` with the App Group created in the steps above.trtcCloud.startScreenCapture(TRTCVideoEncParam(videoFps: 10,videoResolution: TRTCCloudDef.TRTC_VIDEO_RESOLUTION_1280_720,videoBitrate: 1600,videoResolutionMode: TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAIT,),iosAppGroup,);// Stop screen sharingawait trtcCloud.stopScreenCapture();// Event notification for the start of screen sharing, which can be received through `TRTCCloudListener`onRtcListener(type, param){if (type == TRTCCloudListener.onScreenCaptureStarted) {// Screen sharing starts.}}
replay_kit_launcher
plugin to your project.ReplayKitLauncher.launchReplayKitBroadcast(iosExtensionName);
in the response function of the button to activate the screen sharing feature.// Customize a response for button tapping.onShareClick() async {if (Platform.isAndroid) {if (await SystemAlertWindow.requestPermissions) {MeetingTool.showOverlayWindow();}} else {// The screen sharing feature can only be tested on a real device.ReplayKitLauncher.launchReplayKitBroadcast(iosExtensionName);}}
TRTCVideoStreamType
parameter as TRTCVideoStreamTypeSub
when calling the startScreenCapture
interface.TRTCVideoStreamType
parameter as TRTCVideoStreamTypeBig
when calling the startScreenCapture
interface.encParams
in startScreenCapture(), you can specify the encoding quality of screen sharing, including resolution, bitrate, and frame rate. We provide the following suggested reference values:Clarity Level | Resolution | Frame Rate | Bitrate |
Ultra HD (HD+) | 1920 × 1080 | 10 | 800kbps |
HD | 1280 × 720 | 10 | 600kbps |
SD | 960 × 720 | 10 | 400kbps |
encParams
to null, the SDK will automatically use the previously set encoding parameters.TRTCCloudListener
.
Users who want to watch the shared screen can call the startRemoteView API to start rendering the primary stream of the remote user.
Was this page helpful?