VideoSurface Methods - Unity
SetVideo()โ
Manages video streams for both local and remote participants.
-
For the Local Participant:
SetVideo(true)
: Enables the local webcam.SetVideo(false)
: Disables the local webcam.
-
For Remote Participants:
SetVideo(true)
: Sends a request to the remote participant to enable their video.- The remote user receives an OnWebcamRequestedCallback event to accept/reject.
SetVideo(false)
: Disables the remote participant's video.
Parametersโ
-
status:
bool
- Pass
true
to enable the webcam. - Pass
false
to disable the webcam.
- Pass
-
CustomVideoStream:
object
-
Custom configuration for the stream settings. This parameter is optional.
- Default :
videoEncoder
=h240p_w320p
for Android & iOS.
- Default :
-
Parameters:
- videoEncoder:
VideoEncoderConfig
(Optional)- Default :
h144p_w176p
for Android,h90p_w160p
for iOS
- Default :
- isMultiStream:
bool
(Optional)- Default:
true
- Default:
- videoDevice:
VideoDevice
(Optional)- Default: Front camera
- videoEncoder:
-
Note: The
customVideoStream
parameter is only available for local participants. If not provided, the default video configuration will be used.
Returnsโ
void
Exampleโ
if (participant != null && participant.IsLocal)
{
// Enable local webcam (default settings)
participant.SetVideo(true);
// To disable: participant.SetVideo(false);
// To use custom settings:
// CustomVideoStream customStream = new CustomVideoStream(VideoEncoderConfig.h720p_w1280p, false, selectedVideoDevice);
// participant.SetVideo(true, customStream);
}
// --- Remote Participant ---
if (participant != null && !participant.IsLocal)
{
// Request remote participant to enable their video
participant.SetVideo(true);
// To request disable: participant.SetVideo(false);
}
SetAudio()โ
Manages audio streams (microphone) for both local and remote participants.
- For the Local Participant:
SetAudio(true)
: Enables (unmutes) the local microphone.SetAudio(false)
: Disables (mutes) the local microphone.
- For Remote Participants:
SetAudio(true)
: Sends a request to the remote participant to enable their microphone.- The remote user receives an OnMicRequestedCallback event to accept/reject.
SetAudio(false)
: Disables the remote participant's microphone.
Parametersโ
- status:
bool
- Pass
true
to enable the microphone. - Pass
false
to disable the microphone.
- Pass
Returnsโ
void
Exampleโ
// --- Local Participant ---
if (localParticipant != null && localParticipant.IsLocal)
{
// Enable local microphone
localParticipant.SetAudio(true);
// To disable: localParticipant.SetAudio(false);
}
// --- Remote Participant ---
if (remoteParticipant != null && !remoteParticipant.IsLocal)
{
// Request remote participant to enable their microphone
remoteParticipant.SetAudio(true);
// To request disable: remoteParticipant.SetAudio(false);
}
SetParticipant()โ
The SetParticipant()
method is used to associate a specific participant with the VideoSurface
. This allows the VideoSurface
component to render video and manage stream events for that participant.
Parametersโ
- iParticipant: IParticipant
- The
IParticipant
object containing the participant's ID and related information.
- The
Returnsโ
void
Exampleโ
// Called when a participant joins the meeting
private void OnParticipantJoined(IParticipant obj)
{
Debug.Log("Participant Joined: " + obj.ParticipantName);
// Instantiate a new video surface from prefab
VideoSurface participant = Instantiate(_videoSurfacePrefab, _parent).GetComponentInChildren<VideoSurface>();
// Specify that this surface uses RawImage for video rendering
participant.SetVideoSurfaceType(VideoSurfaceType.RawImage);
// Associate the participant with the video surface
participant.SetParticipant(obj);
// Enable stream rendering and callbacks
participant.SetEnable(true);
}
SetVideoSurfaceType()โ
The SetVideoSurfaceType()
method is used to define how the video stream will be rendered on the screenโeither on a UI RawImage
component or on a 3D Renderer
component.
Parametersโ
- type:
VideoSurfaceType
- Specifies the rendering mode for the video stream.
Possible values:VideoSurfaceType.RawImage
: Renders video on a UIRawImage
(e.g., for canvas-based layouts).VideoSurfaceType.Renderer
: Renders video on aRenderer
component (e.g., for 3D objects).VideoSurfaceType.None
: Disables video rendering.
- Specifies the rendering mode for the video stream.
Returnsโ
void
Usageโ
Call this method to explicitly configure the rendering type before associating a participant or setting a texture.
Exampleโ
// Called when a participant joins the meeting
private void OnParticipantJoined(IParticipant obj)
{
Debug.Log("Participant Joined: " + obj.ParticipantName);
// Instantiate a new video surface from prefab
VideoSurface participant = Instantiate(_videoSurfacePrefab, _parent).GetComponentInChildren<VideoSurface>();
// Specify that this surface uses RawImage for video rendering
participant.SetVideoSurfaceType(VideoSurfaceType.RawImage);
// Associate the participant with the video surface
participant.SetParticipant(obj);
// Enable stream rendering and callbacks
participant.SetEnable(true);
}
SetEnable()โ
The SetEnable()
method is used to enable or disable video rendering and associated participant stream callbacks on the VideoSurface
.
Parametersโ
- status:
bool
- Pass
true
to enable rendering and register stream callbacks. - Pass
false
to stop rendering, unregister callbacks, and release the associated texture.
- Pass
Returnsโ
void
Usageโ
Use this method after calling SetParticipant()
to start or stop stream rendering and event handling.
Exampleโ
// Called when a participant joins the meeting
private void OnParticipantJoined(IParticipant obj)
{
Debug.Log("Participant Joined: " + obj.ParticipantName);
// Instantiate a new video surface from prefab
VideoSurface participant = Instantiate(_videoSurfacePrefab, _parent).GetComponentInChildren<VideoSurface>();
// Specify that this surface uses RawImage for video rendering
participant.SetVideoSurfaceType(VideoSurfaceType.RawImage);
// Associate the participant with the video surface
participant.SetParticipant(obj);
// Enable stream rendering and callbacks
participant.SetEnable(true);
}
PauseStream()โ
The PauseStream()
method is used to pause a specific type of media stream (audio or video) for a remote participant.
Parametersโ
- kind:
StreamKind
- The type of stream to pause.
Possible values:StreamKind.AUDIO
StreamKind.VIDEO
- The type of stream to pause.
Returnsโ
void
Exampleโ
// Pause the remote participant's audio stream
if (!participant.IsLocal)
{
participant.PauseStream(StreamKind.AUDIO);
}
ResumeStream()โ
The ResumeStream()
method is used to resume a specific type of media stream (audio or video) from a remote participant.
Parametersโ
- kind:
StreamKind
- The type of stream to resume.
Possible values:StreamKind.AUDIO
StreamKind.VIDEO
- The type of stream to resume.
Returnsโ
void
Exampleโ
if (!participant.IsLocal)
{
participant.ResumeStream(StreamKind.AUDIO);
}
Remove()โ
- It is used to remove a participant from the meeting.
Returnsโ
void
Exampleโ
participant.Remove();
Got a Question? Ask us on discord