Skip to main content
Version: 20 Mar 2024

Player

Media player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.

Inherits from:
IMLMediaPlayer

Public Fields

AudioDRM


public Track.DRM AudioDRM { get; set; }

TypeDescription
Track.DRMMediaDRM to obtain the content keys for decrypting protected media streams.

IsPlaying

Indicates if the media player is currently playing.


public bool IsPlaying { get; set; }


IsPrepared

Indicates if the media player has been prepared.


public bool IsPrepared { get; set; }


Source

The uri/path that the media player is currently set with.


public string Source { get; set; }


VideoDRM


public Track.DRM VideoDRM { get; set; }

TypeDescription
Track.DRMMediaDRM to obtain the content keys for decrypting protected media streams.

VideoRenderer

Media player video renderer


public MLNativeSurfaceYcbcrRenderer VideoRenderer { get; set; }


Public Methods

void CreateVideoRenderer

public void CreateVideoRenderer(
uint width,
uint height
)

Parameters

TypeNameDescription
uintwidth
uintheight

void Destroy

public void Destroy()

MLResult GetDurationMS

public MLResult GetDurationMS(
out int duration
)

Parameters

TypeNameDescription
out intduration

int GetDurationMilliseconds

Gets the duration of the video in milliseconds

public int GetDurationMilliseconds()

Returns: Duration of the video, -1 on failure.

Reimplements: GetDurationMilliseconds


ulong GetFrameDropThresholdMs

public ulong GetFrameDropThresholdMs()

int GetHeight

Get the height of the video in pixels

public int GetHeight()

Returns: The height of the video, -1 on failure.

Reimplements: GetHeight


MLResult GetPositionMS

public MLResult GetPositionMS(
out int position
)

Parameters

TypeNameDescription
out intposition

int GetPositionMilliseconds

Gets the current position of the video in milliseconds

public int GetPositionMilliseconds()

Returns: Position of the playback of the video, -1 on failure.

Reimplements: GetPositionMilliseconds


MLResult GetSpatialAudioChannelPosition

public MLResult GetSpatialAudioChannelPosition(
uint channel,
out Vector3 position
)

Parameters

TypeNameDescription
uintchannel
out Vector3position

MLResult GetSpatialAudioEnable

public MLResult GetSpatialAudioEnable(
out bool enabled
)

Parameters

TypeNameDescription
out boolenabled

bool GetState

public bool GetState(
PollingStateFlags stateFlags
)

Parameters

TypeNameDescription
PollingStateFlagsstateFlagsComment Needed!

int GetVideoBitrate

public int GetVideoBitrate()

MLResult GetVideoSize

public MLResult GetVideoSize(
out int width,
out int height
)

Parameters

TypeNameDescription
out intwidth
out intheight

int GetWidth

Get the width of the video in pixels

public int GetWidth()

Returns: The width of the video, -1 on failure.

Reimplements: GetWidth


delegate void OnBufferingUpdateDelegate

Delegate for the the OnBufferingUpdate event.

public delegate void OnBufferingUpdateDelegate(
MLMedia.Player mediaPlayer,
float percent
)

Parameters

TypeNameDescription
MLMedia.PlayerpercentThe percent of buffering completed for the set source.
floatpercent

delegate void OnCaptionsTextDelegate

Delegate for the any OnCaptionsText event.

public delegate void OnCaptionsTextDelegate(
MLMedia.Player mediaPlayer,
string text
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
stringtext

delegate void OnDRMTrackInfoDelegate

Delegate for the any OnDRMTrackInfo event.

public delegate void OnDRMTrackInfoDelegate(
MLMedia.Player mediaPlayer,
MLMedia.Player.Track.DRM.Info trackDRMInfo
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
MLMedia.Player.Track.DRM.InfotrackDRMInfoMediaPlayer DRMInfo for a Media Track.

delegate void OnErrorDelegate

Delegate for the any OnError event.

public delegate void OnErrorDelegate(
MLMedia.Player mediaPlayer,
MLResult.Code errorCode
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
MLResult.CodeerrorCodeIdentifier of Magic Leap API results

delegate void OnInfoDelegate

Delegate for the the OnInfo event.

public delegate void OnInfoDelegate(
MLMedia.Player mediaPlayer,
MLMedia.Player.Info info
)

Parameters

TypeNameDescription
MLMedia.PlayerinfoThe info event that has occured.
MLMedia.Player.InfoinfoIndicates various trigger various media player actions. MLMediaPlayerInfo from ml_media_player.h .

delegate void OnMediaPlayerGeneralDelegate

Delegate for the any OnMediaPlayerGeneral events (events that only return the mediaPlayer reference)

public delegate void OnMediaPlayerGeneralDelegate(
MLMedia.Player mediaPlayer
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.

delegate void OnTimedTextUpdateDelegate

Delegate for the the OnTimedTextUpdate event.

public delegate void OnTimedTextUpdateDelegate(
MLMedia.Player mediaPlayer,
ulong timedText
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
ulongtimedText

delegate void OnTrackFoundDelegate

Delegate for the any OnTrackFound event.

public delegate void OnTrackFoundDelegate(
MLMedia.Player mediaPlayer,
Track track
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
TracktrackTrack from the prepared source that can be selected by the media player.

delegate void OnTrackSelectedDelegate

Delegate for the any OnTrackSelected event.

public delegate void OnTrackSelectedDelegate(
MLMedia.Player mediaPlayer,
Track selectedTrack
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
TrackselectedTrackTrack from the prepared source that can be selected by the media player.

delegate void OnVideoSizeChangedDelegate

Delegate for the any OnVideoSizeChanged event.

public delegate void OnVideoSizeChangedDelegate(
MLMedia.Player mediaPlayer,
int width,
int height
)

Parameters

TypeNameDescription
MLMedia.PlayermediaPlayerMedia player script that allows playback of a streaming video (either from file or web URL) This script will update the main texture parameter of the Renderer attached as a sibling with the video frame from playback. Audio is also handled through this class and will playback audio from the file.
intwidth
intheight

MLResult Pause

Pauses the video.

public MLResult Pause()

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: Pause


MLResult Play

Plays the video.

public MLResult Play()

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: Play


Player

Constructor for the media player object.

public Player(
out MLResult result
)

Parameters

TypeNameDescription
out MLResultresultThe native result for creating the media player.

Returns: An initialized media player object.


void PollForMetaData

public void PollForMetaData()

MLResult PollState

public MLResult PollState(
PollingStateFlags stateFlags,
out PollingStateFlags state
)

Parameters

TypeNameDescription
PollingStateFlagsstateFlagsComment Needed!
out PollingStateFlagsstateComment Needed!

MLResult PollStates

public MLResult PollStates(
out PollingStateFlags states
)

Parameters

TypeNameDescription
out PollingStateFlagsstatesComment Needed!

MLResult PreparePlayer

public MLResult PreparePlayer()

MLResult PreparePlayerAsync

public MLResult PreparePlayerAsync()

MLResult Reset

public MLResult Reset()

MLResult ResetAsync

public MLResult ResetAsync()

MLResult Resume

Resume the video.

public MLResult Resume()

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: Resume


MLResult Seek

Seeks the specified time in the video.

public MLResult Seek(
int positionSeconds,
SeekMode seekMode
)

Parameters

TypeNameDescription
intpositionSecondsAbsolute time to seek to.
SeekModeseekModeMode indicating where exactly to seek to.

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: Seek


MLResult SelectTrack

public MLResult SelectTrack(
int index
)

Parameters

TypeNameDescription
intindex

MLResult SelectTrack

public MLResult SelectTrack(
Track track
)

Parameters

TypeNameDescription
TracktrackTrack from the prepared source that can be selected by the media player.

void SetFrameDropThresholdMs

public void SetFrameDropThresholdMs(
ulong threshold
)

Parameters

TypeNameDescription
ulongthreshold

MLResult SetLooping

Sets the loop flag for the video.

public MLResult SetLooping(
bool loop
)

Parameters

TypeNameDescription
boolloopFlag to loop

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: SetLooping


MLResult SetSourcePath

Sets the source path that the media player will play content from.

public MLResult SetSourcePath(
string source
)

Parameters

TypeNameDescription
stringsourcePath of the media that's on the device.

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded. MLResult.Result will be MLResult.Code.InvalidParam if failed due to an invalid input parameter. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. MLResult.Result will be MLResult.Code.MediaGenericNoInit if media player was not properly built or initialized. MLResult.Result will be MLResult.Code.PermissionDenied if attempting to access web content without appropriate network permissions

Reimplements: SetSourcePath


MLResult SetSourceURI

Sets the source path that the media player will play content from.

public MLResult SetSourceURI(
string source
)

Parameters

TypeNameDescription
stringsourceURI of the media.

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded. MLResult.Result will be MLResult.Code.InvalidParam if failed due to an invalid input parameter. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to internal error. MLResult.Result will be MLResult.Code.MediaGenericNoInit if media player was not properly built or initialized. MLResult.Result will be MLResult.Code.PermissionDenied if attempting to access web content without appropriate network permissions

Reimplements: SetSourceURI


MLResult SetSpatialAudioChannelPosition

public MLResult SetSpatialAudioChannelPosition(
uint channel,
Vector3 position
)

Parameters

TypeNameDescription
uintchannel
Vector3position

MLResult SetSpatialAudioEnable

public MLResult SetSpatialAudioEnable(
bool enable
)

Parameters

TypeNameDescription
boolenable

MLResult SetStreamingSourcePath

public MLResult SetStreamingSourcePath(
string path
)

Parameters

TypeNameDescription
stringpath

MLResult SetVolume

Sets the volume of the video.

public MLResult SetVolume(
float vol
)

Parameters

TypeNameDescription
floatvolVolume between 0 and 1.

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: SetVolume


MLResult Stop

Stops the video in the editor.

public MLResult Stop()

Returns: MLResult.Result will be MLResult.Code.Ok if operation succeeded.

Reimplements: Stop


void UnlinkDataSource

public void UnlinkDataSource()

MLResult UnselectTrack

public MLResult UnselectTrack(
Track track
)

Parameters

TypeNameDescription
TracktrackTrack from the prepared source that can be selected by the media player.

Public Attributes

TTMLMime


public const string TTMLMime = "application/ttml+xml";


VTTMime


public const string VTTMime = "text/vtt";


Public Events

OnBufferingUpdate

Event used to listen for when the media player is buffering.

public OnBufferingUpdateDelegate OnBufferingUpdate()

OnCEA608

public OnCaptionsTextDelegate OnCEA608()

OnCEA708

public OnCaptionsTextDelegate OnCEA708()

OnCompletion

Event used to listen for the media player has completed playing it's source.

public OnMediaPlayerGeneralDelegate OnCompletion()

OnDRMTrackInfo

public OnDRMTrackInfoDelegate OnDRMTrackInfo()

OnError

Event used to listen for when the media player has an error.

public OnErrorDelegate OnError()

OnFrameAvailable

Event used to listen for when the media player frame is available (used for rendering purposes).

public OnMediaPlayerGeneralDelegate OnFrameAvailable()

OnFramePacking

Event used to listen for when the frames are packed.

public OnMediaPlayerGeneralDelegate OnFramePacking()

OnInfo

Event used to listen for when information about the media player, see the MLMedia.Player.Info enum for the types of information given.

public OnInfoDelegate OnInfo()

OnMediaSubtitleUpdate

Event used to listen for when subtitles are updated.

public OnMediaPlayerGeneralDelegate OnMediaSubtitleUpdate()

OnPause

Event used to listen for when Pause() has been called.

public OnMediaPlayerGeneralDelegate OnPause()

OnPlay

Event used to listen for when Play() has been called.

public OnMediaPlayerGeneralDelegate OnPlay()

OnPrepared

Event used to listen for when the media player has finished preparing.

public OnMediaPlayerGeneralDelegate OnPrepared()

OnResetComplete

Event used to listen for when the media player resets.

public OnMediaPlayerGeneralDelegate OnResetComplete()

OnSeekComplete

Event used to listen for when the media player has finished seeking.

public OnMediaPlayerGeneralDelegate OnSeekComplete()

OnStop

Event used to listen for when Stop() has been called.

public OnMediaPlayerGeneralDelegate OnStop()

OnTimedText

Event used to listen for when timed text apppears.

public OnCaptionsTextDelegate OnTimedText()

OnTrackFound

public OnTrackFoundDelegate OnTrackFound()

OnTrackSelected

public OnTrackSelectedDelegate OnTrackSelected()

OnVideoSizeChanged

Event used to listen for when the video size changes.

public OnVideoSizeChangedDelegate OnVideoSizeChanged()

Public Enums

AudioChannel

Enumeration of the available audio channel indices in 5.1 SMPTE order.

EnumeratorValueDescription
FrontLeft0Front left channel index.
FrontRight1Front right channel index.
FrontCenter2Front center channel index.
LowFrequencyEffects3Low frequency effects channel index.
SurroundLeft4Surround left channel index.
SurroundRight5Surround right channel index.

BufferingMode

Comment Needed!

EnumeratorValueDescription
NoneDo not support buffering.
TimeOnlySupport only time based buffering.
SizeOnlySupport only size based buffering.
TimeThenSizeSupport both time and size based buffering, time based calculation precedes size based. Size based calculation will be used only when time information is not available for the stream.

Cea608CaptionColor

CEA608 caption color code. MLCea608CaptionColor from ml_media_cea608_caption.h .

EnumeratorValueDescription
White0CEA608 caption color is white.
Green1CEA608 caption color is green.
Blue2CEA608 caption color is blue.
Cyan3CEA608 caption color is cyan. >
Red4CEA608 caption color is red.
Yellow5CEA608 caption color is yellow.
Magenta6CEA608 caption color is magenta.
Invalid7CEA608 caption color is invalid.

Cea608CaptionDimension

CEA608 caption Dimension constants. MLCea608CaptionDimension from ml_media_cea608_caption.h .

EnumeratorValueDescription
MaxRows15Max number of rows.
MaxCols32Max number of columns.
MaxRowsPlus217Max number of plus 2.
MaxColsPlus234Max number of columns plus 2.

Cea608CaptionStyle

CEA608 caption style code. MLCea608CaptionStyle from ml_media_cea608_caption.h .

EnumeratorValueDescription
Normal0x00000000CEA608 caption style code is normal.
Italics0x00000001CEA608 caption style code is italics.
Underline0x00000002CEA608 caption style code is underline.

Cea708CaptionColorOpacity

CEA708 Caption Color Opacity constants. MLCea708CaptionColorOpacity from ml_media_cea708_caption.h .

EnumeratorValueDescription
Solid0Solid opacity.
Flash1Flashing opacity.
Translucent2Translucent opacity.
Transparent3Transparent opacity.

Cea708CaptionEmitCommand

CEA708 Caption Emit Commands constants. MLCea708CaptionEmitCommand from ml_media_cea708_caption.h .

EnumeratorValueDescription
Buffer1Buffer command.
Control2Control command.
CWX3SetCurrentWindow tells the caption decoder which window the following commands describe:
  • SetWindowAttributes
  • SetPenAttributes
  • SetPenColor
  • SetPenLocation. If the window specified has not already been created with a DefineWindow command then, SetCurrentWindow and the window property commands can be safely ignored. | | CLW | 4| ClearWindows clears all the windows specified in the 8 bit window bitmap. | | DSW | 5| DisplayWindows displays all the windows specified in the 8 bit window bitmap. | | HDW | 6| HideWindows hides all the windows specified in the 8 bit window bitmap. | | TGW | 7| ToggleWindows hides all displayed windows, and displays all hidden windows specified in the 8 bit window bitmap. | | DLW | 8| DeleteWindows deletes all the windows specified in the 8 bit window bitmap. If the current window, as specified by the last SetCurrentWindow command, is deleted then the current window becomes undefined and the window attribute commands should have no effect until after the next SetCurrentWindow or DefineWindow command. | | DLY | 9| Delay suspends all processing of the current service, except for DelayCancel and Reset scanning. | | DLC | 10| DelayCancel terminates any active delay and resumes normal command processing. DelayCancel should be scanned for during a Delay. | | RST | 11| Reset deletes all windows, cancels any active delay, and clears the buffer before the Reset command. Reset should be scanned for during a Delay. | | SPA | 12| The SetPenAttributes command specifies how certain attributes of subsequent characters are to be rendered in the current window, until the next SetPenAttributes command. | | SPC | 13| SetPenColor sets the foreground, background, and edge color for the subsequent characters. | | SPL | 14| SetPenLocation sets the location of for the next bit of appended text in the current window. It has two parameters, row and column. | | SWA | 15| SetWindowAttributes Sets the window attributes of the current window. | | DFX | 16| DefineWindow0-7 creates one of the eight windows used by a caption decoder. |

Cea708CaptionEmitCommandControl

CEA708 Caption Emit Command Control constants. MLCea708CaptionEmitCommandControl from ml_media_cea708_caption.h .

EnumeratorValueDescription
ETX0x03End of text.
BS0x08Back space.
FF0x0cThis code is equivalent to CEA708 CLW command
HCR0x0eCarriage return.

Cea708CaptionPenOffset

CEA708 Caption Pen Offset constants. MLCea708CaptionPenOffset from ml_media_cea708_caption.h .

EnumeratorValueDescription
Subscript0Subscript offset.
Normal1Normal offset.
Superscript2Superscript offset.

Cea708CaptionPenSize

CEA708 Caption Pen Size constants. MLCea708CaptionPenSize from ml_media_cea708_caption.h .

EnumeratorValueDescription
Small0Small pen size.
Standard1Standard pen size.
Large2Large pen size.

FramePackingFlags

Frame Packing Arrangement flags for stereoscopic videos.

EnumeratorValueDescription
None0No flags.
RightViewFirst1Right view first.
LeftFlipped2Left view flipped.
RightFlipped4Right view flipped.
Anaglyph_RedCyan8Anaglyph red/cyan.
AnaglyphGreenMagenta16Anaglyph green/magenta.

FramePackingMode

Frame Packing Arrangement for stereoscopic videos.

EnumeratorValueDescription
None0Not a stereoscopic video.
CheckboardCheckboard.
ColumnInterleavedColumn interleaved.
RowInterleavedRow interleaved.
SideBySideQuincunxSide by side quincunx.
SideBySideSide by side.
TopBottomTop bottom.
MultiviewFrameByFrameMultiview frame by frame.
FrameByFrameFrame by frame.
AnaglyphAnaglyph.

Info

Indicates various trigger various media player actions. MLMediaPlayerInfo from ml_media_player.h .

EnumeratorValueDescription
Unknown1Unknown status
StartedAsNext2The player was started because it was used as the next player.
RenderingStart3The player just pushed the very first video frame for rendering.
Looping4The player just reached EOS and started from beginning loop.
Started5The player acknowledgement that it has started playing.
Paused6The player acknowledgement that it has paused.
Stopped7The player acknowledgement that it has stopped playing.
StartedBySharedPlayer8The player acknowledgement that it has started playing as result of shared player's request.
PausedBySharedPlayer9The player acknowledgement that it has paused playing as result of shared player's request.
SeekBySharedPlayer10The player acknowledgement that it is seeking as result of shared player's request.
StoppedBySharedPlayer11The player acknowledgement that it has stopped playing as result of shared player's request.
SyncStart12The Media player has started sync'ing with other shared players.
SyncComplete13The Media player has completed sync'ing with other shared players.
VideoTrackLagging700The video is too complex for the decoder: it can't decode frames fast enough.
BufferingStart701Media player is temporarily pausing playback.
BufferingEnd702Media player is resuming playback after filling buffers.
NetworkBandwidth703Network bandwidth info.
BehindLiveWindow704The player is Behind Live Window.
PowerStatePause705Media player is paused because device is in sleep or standby state.
PowerStateResume706Media player has resumed playback because device has returned from sleep or standby state.
BufferedDuration707Duration in milliseconds of buffered content.
BadInterleaving800Bad interleaving means that a media has been improperly interleaved.
NotSeekable801The media is not seekable e.g live stream.
MetadataUpdate802New media metadata is available.
PlayAudioError804Audio can not be played.
PlayVideoError805Video can not be played.
TimedTextError900Media timed text error.

PollingStateFlags

Comment Needed!

EnumeratorValueDescription
IsPlaying1 << 0Playing.
IsLooping1 << 1Looping.
HasBeenPrepared1 << 2Prepared.
HasPlaybackCompleted1 << 3Playback completed.
HasSeekCompleted1 << 4Seek completed.
HasSizeChanged1 << 5Size changed.
HasBufferingUpdated1 << 6Buffering updated.
HasReceivedInfo1 << 7Received info.
HasReceivedError1 << 8Recieved error.
HasTimedTextUpdated1 << 9Timed text updated.
HasSubtitleUpdated1 << 10Subtitle updated.
HasMetadataUpdated1 << 11Metadata updated.
HasDrmInfoUpdated1 << 12DRM info updated.
HasResetCompleted1 << 13Async Reset completed.
All~0uAll states.

SeekMode

Mode indicating where exactly to seek to.

EnumeratorValueDescription
PreviousSync0Seek to the previous key frame.
NextSyncSeek to the next key frame.
ClosestSyncSeek to the closest key frame.
ClosestSeek to the closest frame, more accurate but slower.

VideoScalingMode

VideoScalingMode.

EnumeratorValueDescription
ScaleToFit1Scale to fit.
ScaleToFitWithCropping2Scale to fit with cropping.