Skip to main content
Version: 2.x.x

VideoSurface Methods - Unity


SetVideo()โ€‹

The SetVideo() method is used to enable or disable the webcam (video stream) for the local participant.

Parametersโ€‹

  • status: bool
    • Pass true to enable the webcam.
    • Pass false to disable the webcam.

Returnsโ€‹

  • void

Exampleโ€‹

if (videosurface.IsLocal)
{
// Enable webcam
videosurface.SetVideo(true);

// Disable webcam
// participant.SetVideo(false);
}
else
{
Debug.LogWarning("SetVideo can only be called on the local participant.");
}

SetAudio()โ€‹

The SetAudio() method is used to enable or disable the microphone (audio stream) for the local participant.

Parametersโ€‹

  • status: bool
    • Pass true to enable the microphone.
    • Pass false to disable the microphone.

Returnsโ€‹

  • void

Exampleโ€‹

if (participant.IsLocal)
{
// Enable microphone
participant.SetAudio(true);

// Disable microphone
// participant.SetAudio(false);
}
else
{
Debug.LogWarning("SetAudio can only be called on the local participant.");
}

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.

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 UI RawImage (e.g., for canvas-based layouts).
      • VideoSurfaceType.Renderer: Renders video on a Renderer component (e.g., for 3D objects).
      • VideoSurfaceType.None: Disables video rendering.

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.

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

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

Returnsโ€‹

  • void

Exampleโ€‹

if (!participant.IsLocal)
{
participant.ResumeStream(StreamKind.AUDIO);
}

Got a Question? Ask us on discord