Skip to main content
Version: 20 Mar 2024

Track

Struct that represents a media stream track object.

Inherited by:
UnityEngine.XR.MagicLeap.MLWebRTC.AppDefinedSource

Public Fields

Id

Track name


public string Id { get; set; }


IsLocal

Gets or sets a value indicating whether the track is local or not.


public bool IsLocal { get; set; }


ParentConnection

Gets a reference to the associated connection of the track.


public MLWebRTC.PeerConnection ParentConnection { get; set; }

TypeDescription
MLWebRTC.PeerConnectionClass that represents a connection used by the MLWebRTC API.

Streams

Gets the list of streams associated with this track.


public List< MediaStream > Streams { get; set; }

TypeDescription
List< MediaStream >Class that represents a media stream object.

TrackType

Gets the string that determines the type of track this is.


public Type TrackType { get; set; }

TypeDescription
TypeDefines the types of tracks that can exist.

Public Methods

Track CreateAudioTrackFromMicrophone

Creates an initialized Track object.

public static Track CreateAudioTrackFromMicrophone(
out MLResult result,
string trackId =""
)

Parameters

TypeNameDescription
out MLResultresultThe MLResult object of the inner platform call(s).
stringtrackId

Returns: An initialized Track object.


Track CreateAudioTrackFromSource

Creates an initialized Track object.

public static Track CreateAudioTrackFromSource(
out MLResult result,
string trackId =""
)

Parameters

TypeNameDescription
out MLResultresultThe MLResult object of the inner platform call(s).
stringtrackId

Returns: An initialized Track object.


Track CreateVideoTrack

Creates an initialized Track object. Recommended to use app defined video sources in production, with sample 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 Track CreateVideoTrack(
VideoType videoType,
out MLResult result,
string trackId =""
)

Parameters

TypeNameDescription
VideoTypevideoTypeThe type of video source to use.
out MLResultresultThe MLResult object of the inner platform call(s).
stringinputContextThe InputContext object to start the MLMRCamera API with.

Returns: An initialized Track object.


MLResult DestroyLocal

Destroys the Track and its associated media source.

public virtual MLResult DestroyLocal()

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent.

Reimplemented by: DestroyLocal, DestroyLocal


MLResult GetEnabled

Gets if a track is currently enabled or not.

public MLResult GetEnabled(
out bool isEnabled
)

Parameters

TypeNameDescription
out boolisEnabledTrue if the track is enabled.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent. MLResult.Result will be MLResult.Code.InvalidParam if an invalid parameter was passed.


MLResult SetEnabled

Sets a track to be enabled or disabled.

public MLResult SetEnabled(
bool isEnabled
)

Parameters

TypeNameDescription
boolisEnabledTrue if the track should be enabled.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent.


Protected Methods

HandleDeviceActive

Sets this track to enabled during the lifecycle active event. Override for custom behavior.

protected virtual void HandleDeviceActive()

HandleDeviceReality

Disables this track during the lifecycle reality events. Override for custom behavior.

protected virtual void HandleDeviceReality()

HandleDeviceStandby

Disables this track during the lifecycle standby event. Override for custom behavior.

protected virtual void HandleDeviceStandby()

OnApplicationPause

Reacts to when the application is paused (after subscribing to MLDevice). Override for custom behavior.

protected virtual void OnApplicationPause(
bool pause
)

Parameters

TypeNameDescription
boolpauseTrue if paused.

Reimplemented by: OnApplicationPause


Protected Attributes

wasEnabledBeforeLifecycleStateChange

Caches if the track was enabled before a lifestyle event change.


protected bool wasEnabledBeforeLifecycleStateChange = false;


Public Enums

AudioType

Defines the natively supported audio types.

EnumeratorValueDescription
NoneNo audio source.
MicrophoneNatively uses Microphone as audio source.
DefinedUses a custom audio source.

Type

Defines the types of tracks that can exist.

EnumeratorValueDescription
AudioAudio track type.
VideoVideo track type.

VideoType

Defines the natively supported video types. It is recommended to use app defined video sources in production, with sample sources provided as MLWebRTC.MLCameraVideoSource in the UnityEngine.XR.MagicLeap namespace since those sources provide more information about and control over the camera configuration.

EnumeratorValueDescription
NoneNo video source.
MLCameraNatively uses MLCamera as video source.
MLMRCameraNatively uses MLMRCamera as video source.
VirtualOnlyNatively uses VirtualOnly as video source.