Skip to main content
Version: 20 Mar 2024

MediaStream

Class that represents a media stream object.

Public Fields

ActiveAudioTrack

Gets the active audio track.


public MediaStream.Track ActiveAudioTrack { get; set; }

TypeDescription
MediaStream.TrackStruct that represents a media stream track object.

ActiveVideoTrack

Gets the active video track.


public MediaStream.Track ActiveVideoTrack { get; set; }

TypeDescription
MediaStream.TrackStruct that represents a media stream track object.

AudioTracks

Gets all audio tracks.


public List< MediaStream.Track > AudioTracks { get; set; }

TypeDescription
List< MediaStream.Track >Struct that represents a media stream track object.

Id

Gets the id of this media stream.


public string Id = new HashSet<PeerConnection>() { get; set; }


IsLocal

Gets a value indicating whether the media stream is local or not.


public bool IsLocal { get; set; }


ParentConnections

Gets the connections associated with this media stream. Remote media streams will have just 1 connection, while local streams can have more than one, depending on the app setup.


public HashSet< MLWebRTC.PeerConnection > ParentConnections { get; set; }

TypeDescription
HashSet< MLWebRTC.PeerConnection >Class that represents a connection used by the MLWebRTC API.

Tracks

Gets the list of tracks associated with this media stream.


public List< MediaStream.Track > Tracks { get; set; }

TypeDescription
List< MediaStream.Track >Struct that represents a media stream track object.

VideoTracks

Gets all video tracks.


public List< MediaStream.Track > VideoTracks { get; set; }

TypeDescription
List< MediaStream.Track >Struct that represents a media stream track object.

Public Methods

MLResult AddLocalTrack

Adds a local track to the media stream.

public MLResult AddLocalTrack(
MLWebRTC.MediaStream.Track track
)

Parameters

TypeNameDescription
MLWebRTC.MediaStream.TrackconnectionThe connection to use.
trackThe local track to add.

Returns:


MediaStream Create

Creates an initialized local MediaStream object.

public static MediaStream Create(
string id
)

Parameters

TypeNameDescription
stringidThe id to give the media stream.

Returns: An initialized MediaStream object.


MediaStream CreateWithAppDefinedVideoTrack

Creates an initialized local MediaStream object and it's tracks with the given video source.

public static MediaStream CreateWithAppDefinedVideoTrack(
string id,
MLWebRTC.AppDefinedVideoSource appDefinedVideoSource,
Track.AudioType audioType,
string audioTrackId ="",
MLWebRTC.AppDefinedAudioSource localDefinedAudioSource =null
)

Parameters

TypeNameDescription
stringconnectionConnection to use.
MLWebRTC.AppDefinedVideoSourceidThe id to give the media stream.
Track.AudioTypeappDefinedVideoSourceThe defined video source to use.
stringaudioTrackId
MLWebRTC.AppDefinedAudioSourcelocalDefinedAudioSourceClass that represents an app defined video source that can be used by the MLWebRTC API.

Returns: An initialized MediaStream object.


MediaStream CreateWithBuiltInTracks

Creates an initialized local MediaStream object and it's tracks with the given video type. Recommended to use CreateWithAppDefinedVideoTrack() in production, with sample video sources provided as MLCameraVideoSource and MLMRCameraVideoSource in the UnityEngine.XR.MagicLeap namespace since those sources provide more information about and control over various error cases and handle special cases like app pause/resume and device standby/reality/active.

public static MediaStream CreateWithBuiltInTracks(
string id,
Track.VideoType videoType,
Track.AudioType audioType,
string videoTrackId ="",
string audioTrackId =""
)

Parameters

TypeNameDescription
stringconnectionConnection to use.
Track.VideoTypeidThe id to give the media stream.
Track.AudioTypevideoTypeThe type of video to use.
stringvideoTrackId
stringaudioTrackId

Returns: An initialized MediaStream object.


void DestroyLocal

Destroys this stream and it's associated tracks.

public void DestroyLocal()

MLResult RemoveLocalTrack

Removes a local track from the media stream.

public MLResult RemoveLocalTrack(
MLWebRTC.MediaStream.Track track
)

Parameters

TypeNameDescription
MLWebRTC.MediaStream.TrackconnectionThe connection to use.
trackThe local track to add.

Returns:


MLResult SelectTrack

Sets the given track as the active track of it's kind and enables it.

public MLResult SelectTrack(
MediaStream.Track track
)

Parameters

TypeNameDescription
MediaStream.TracktrackThe track to make active.

MLResult UnSelectTrack

Sets the given track to longer be the active track of it's kind and disables.

public MLResult UnSelectTrack(
MediaStream.Track track
)

Parameters

TypeNameDescription
MediaStream.TracktrackThe track to make inactive.