Skip to main content
Version: 0.0.x

Share Your Screen

  • Whenever any participant wants to share a complete screen of mobile, they can simply do it with VideoSDK Meeting.

  • This guide will provide an overview of how to enable or disable Screen Share in a meeting.

How Screen share works?

  • The following diagram shows flow of the screen sharing in android using VideoSDK:

VideoSDK Android Screenshare Flow Diagram

Enable Screen Share

  • A participant’s Screen share stream is provided via the MediaProjection API. This API is only compatible with Build.VERSION_CODES.LOLLIPOP or higher.

  • Get an instance of the MediaProjectionManager and Call the createScreenCaptureIntent() method in an activity. This initiates a prompt dialog for the user to confirm screen projection.

  • One will get a prompt dialog like this:

user permission

  • After permission is received from the user, call meeting.enableScreenShare() method.
private fun enableScreenShare() {
val mediaProjectionManager = application.getSystemService(
MEDIA_PROJECTION_SERVICE
) as MediaProjectionManager
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE
)
}

public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE) return
if (resultCode == RESULT_OK) {
meeting!!.enableScreenShare(data)
}
}

Customise notification

  • When a presenter starts screen share, presenter will receive a notification with a pre-defined title and message.

  • Notification with pre-defined title and message will look like this:

notification
  • You can Customise those title, message and icon as per your requirements using <meta-data> specified in app/src/main/AndroidManifest.xml.
<application>
<meta-data
android:name="notificationTitle"
android:value="@string/notificationTitle"
/>
<meta-data
android:name="notificationContent"
android:value="@string/notificationContent"
/>
<meta-data
android:name="notificationIcon"
android:resource="@mipmap/ic_launcher_round"
/>
</application>

Disable Screen Share

By using meeting.disableScreenShare() function, a participant can stop publishing screen stream to other participants.

private fun disableScreenShare() {
meeting!!.disableScreenShare()
}

Display Screen Share Stream

Local Participant

When a Local participant share the screen, onStreamEnabled() of ParticipantEventListener is triggered with the Stream which can be added to a SurfaceViewRenderer.

override fun onCreate(savedInstanceState: Bundle?) {
//...
svrShare!!.init(PeerConnectionUtils.getEglContext(), null)
}

private fun setLocalListeners() {
meeting!!.localParticipant.addEventListener(object : ParticipantEventListener() {
override fun onStreamEnabled(stream: Stream) {
if (stream.kind.equals("share", ignoreCase = true)) {
// display share video
val videoTrack = stream.track as VideoTrack
videoTrack.addSink(svrShare)
}
}
override fun onStreamDisabled(stream: Stream) {
if (stream.kind.equals("share", ignoreCase = true)) {
val track: VideoTrack? = stream.track as VideoTrack
track?.removeSink(svrShare)
svrShare!!.clearImage()
}
}
});
}

Other Participants

When other participant(Except you) share their screen, onPresenterChanged() in the MeetingEventListener is triggered with the participantId of the screen share.

override fun onCreate(savedInstanceState: Bundle?) {
//...
svrShare!!.init(PeerConnectionUtils.getEglContext(), null)
}

private val meetingEventListener: MeetingEventListener = object : MeetingEventListener() {
override fun onPresenterChanged(participantId: String) {
updatePresenter(participantId)
}
}

//Getting the stream from the participantId
private fun updatePresenter(participantId: String?) {
// find participant
val participant = meeting!!.participants.get(participantId) ?: return

// find share stream in participant
var shareStream: Stream? = null
for (stream: Stream in participant.streams.values) {
if ((stream.kind == "share")) {
shareStream = stream
break
}
}
if (shareStream == null) return

// display share video
val videoTrack = shareStream.track as VideoTrack
videoTrack.addSink(svrShare)

// listen for share stop event
participant.addEventListener(object : ParticipantEventListener() {
override fun onStreamDisabled(stream: Stream) {
if ((stream.kind == "share")) {
val track: VideoTrack? = stream.track as VideoTrack
track?.removeSink(svrShare)

svrShare!!.clearImage()
}
}
})
}