Native Media Player
Search Results for

    Show / Hide Table of Contents

    Class MediaPlayer

    Inheritance
    object
    MediaPlayer
    Namespace: Glitch9.NativeMediaPlayer
    Assembly: .dll
    Syntax
    public static class MediaPlayer

    Properties

    | Edit this page View Source

    BackgroundControlsEnabled

    Show or hide the native background media controls (Android: MediaStyleNotification / iOS: MPNowPlayingInfoCenter). It's sometimes unstable on runtime, so it's recommended to set this property before playing media.

    Declaration
    public static bool BackgroundControlsEnabled { get; set; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    BackgroundPlayEnabled

    Indicates if the background mode is enabled.

    Note that this property DOES NOT have platform-specific implementation and is handled by Glitch9.NativeMediaPlayer scene object within Unity.

    Declaration
    public static bool BackgroundPlayEnabled { get; set; }
    Property Value
    Type Description
    bool
    Remarks

    True by default.

    | Edit this page View Source

    CurrentMediaItem

    Gets the current MediaItem.

    Declaration
    public static MediaItem CurrentMediaItem { get; }
    Property Value
    Type Description
    MediaItem
    | Edit this page View Source

    CurrentMediaItemIndex

    Retrieves the current MediaItem's index from the native side of the plugin.

    Declaration
    public static int CurrentMediaItemIndex { }
    Property Value
    Type Description
    int
    | Edit this page View Source

    CurrentMediaItemUriType

    Declaration
    public static UriType CurrentMediaItemUriType { get; }
    Property Value
    Type Description
    UriType
    | Edit this page View Source

    CurrentPlaylist

    Gets the current playlist.

    Declaration
    public static Playlist CurrentPlaylist { get; }
    Property Value
    Type Description
    Playlist
    | Edit this page View Source

    CurrentPlaylistIndex

    Gets the current Playlist index.

    Declaration
    public static int CurrentPlaylistIndex { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    HasNextMediaItem

    Checks if there is a next MediaItem.

    Declaration
    public static bool HasNextMediaItem { get; }
    Property Value
    Type Description
    bool

    True if there is a next MediaItem; otherwise, false.

    | Edit this page View Source

    HasNextPlaylist

    Checks if there is a next Playlist available.

    Declaration
    public static bool HasNextPlaylist { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    HasPreviousMediaItem

    Checks if there is a previous MediaItem.

    Declaration
    public static bool HasPreviousMediaItem { get; }
    Property Value
    Type Description
    bool

    True if there is a previous MediaItem; otherwise, false.

    | Edit this page View Source

    HasPreviousPlaylist

    Checks if there is a previous Playlist available.

    Declaration
    public static bool HasPreviousPlaylist { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    IsInitialized

    Indicates if the NativeMediaPlayer plugin is initialized.

    Declaration
    public static bool IsInitialized { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    IsLoading

    Indicates if the NativeMediaPlayer plugin is currently loading media from remote URL (http/https).

    Declaration
    public static bool IsLoading { }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    IsPlaying

    Indicates if the NativeMediaPlayer plugin is currently playing media.

    Declaration
    public static bool IsPlaying { }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    IsReady

    Checks if the NativeMediaPlayer plugin is ready to play media.

    Declaration
    public static bool IsReady { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    LastDuration

    Gets the duration of the last played MediaItem.

    Declaration
    public static float LastDuration { get; }
    Property Value
    Type Description
    float
    | Edit this page View Source

    LastError

    Gets the last error message from the NativeMediaPlayer plugin.

    Declaration
    public static string LastError { get; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    LastMediaItemIndex

    Gets the index of the last MediaItem played.

    Declaration
    public static int LastMediaItemIndex { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    LastPosition

    Gets the last playback position of the last played MediaItem.

    Declaration
    public static float LastPosition { get; }
    Property Value
    Type Description
    float
    | Edit this page View Source

    ListenerId

    Name of the listener object in the scene. The listener object in the latest version is Glitch9.NativeMediaPlayer. In previous versions, it was MediaEventListener.

    Declaration
    public static string ListenerId { get; set; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    Logger

    Gets or sets the logger instance.

    Declaration
    public static ILogger Logger { get; set; }
    Property Value
    Type Description
    ILogger
    | Edit this page View Source

    PlaybackState

    Declaration
    public static PlaybackState PlaybackState { get; }
    Property Value
    Type Description
    PlaybackState
    | Edit this page View Source

    Playlists

    Gets the collection of playlists.

    Declaration
    public static IReadOnlyDictionary<int, Playlist> Playlists { get; }
    Property Value
    Type Description
    IReadOnlyDictionary<int, Playlist>
    | Edit this page View Source

    PreBufferDuration

    Controls how many seconds of the MediaItem to pre-buffer before playing when it is StreamingUrl.

    Declaration
    public static int PreBufferDuration { get; set; }
    Property Value
    Type Description
    int
    Remarks

    This property is shared between Unity and native plugins via PlayerPrefs.

    | Edit this page View Source

    RepeatMode

    Repeat mode control property, with platform-specific implementation.

    0: No repeat, 1: Repeat all, 2: Repeat one

    Declaration
    public static RepeatMode RepeatMode { get; set; }
    Property Value
    Type Description
    RepeatMode
    | Edit this page View Source

    SeekIncrement

    Controls how many seconds to seek forward or backward.

    Declaration
    public static int SeekIncrement { get; set; }
    Property Value
    Type Description
    int
    Remarks

    This property is shared between Unity and native plugins via PlayerPrefs.

    | Edit this page View Source

    ShuffleModeEnabled

    Shuffle mode control property, with platform-specific implementation.

    True: Shuffle mode enabled, False: Shuffle mode disabled

    Declaration
    public static bool ShuffleModeEnabled { }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Volume

    Volume control property, with platform-specific implementation.

    Value range: 0.0 to 1.0

    Declaration
    public static float Volume { }
    Property Value
    Type Description
    float
    | Edit this page View Source

    onDownloadProgress

    Called periodically to report download progress of the current media item.

    Declaration
    public static UnityEvent<string, float> onDownloadProgress { get; }
    Property Value
    Type Description
    UnityEvent<string, float>
    | Edit this page View Source

    onInitialized

    Called when the media player is initialized and ready.

    Declaration
    public static UnityEvent onInitialized { get; }
    Property Value
    Type Description
    UnityEvent
    | Edit this page View Source

    onIsLoadingChanged

    Called when the player starts or stops loading media.

    Declaration
    public static UnityEvent<bool> onIsLoadingChanged { get; }
    Property Value
    Type Description
    UnityEvent<bool>
    | Edit this page View Source

    onIsPlayingChanged

    Called when the playback playing state changes (playing or paused).

    Declaration
    public static UnityEvent<bool> onIsPlayingChanged { get; }
    Property Value
    Type Description
    UnityEvent<bool>
    | Edit this page View Source

    onMediaItemTransition

    Called when the media item is changed during playback.

    Declaration
    public static UnityEvent<string> onMediaItemTransition { get; }
    Property Value
    Type Description
    UnityEvent<string>
    | Edit this page View Source

    onPlaybackStateChanged

    Called when the playback state changes (e.g., Playing, Paused, Stopped).

    Declaration
    public static UnityEvent<PlaybackState> onPlaybackStateChanged { get; }
    Property Value
    Type Description
    UnityEvent<PlaybackState>
    | Edit this page View Source

    onPlayerError

    Called when a playback error occurs.

    Declaration
    public static UnityEvent<string> onPlayerError { get; }
    Property Value
    Type Description
    UnityEvent<string>
    | Edit this page View Source

    onPlaylistLoaded

    Called when a playlist is successfully loaded.

    Declaration
    public static UnityEvent onPlaylistLoaded { get; }
    Property Value
    Type Description
    UnityEvent
    | Edit this page View Source

    onRepeatModeChanged

    Called when the repeat mode is changed.

    Declaration
    public static UnityEvent<RepeatMode> onRepeatModeChanged { get; }
    Property Value
    Type Description
    UnityEvent<RepeatMode>
    | Edit this page View Source

    onShuffleModeEnabledChanged

    Called when the shuffle mode is enabled or disabled.

    Declaration
    public static UnityEvent<bool> onShuffleModeEnabledChanged { get; }
    Property Value
    Type Description
    UnityEvent<bool>

    Methods

    | Edit this page View Source

    AddMediaItem(MediaItem, int)

    Adds a MediaItem to the current Playlist.

    Declaration
    public static void AddMediaItem(MediaItem item, int mediaItemIndex = -1)
    Parameters
    Type Name Description
    MediaItem item

    The MediaItem to add.

    int mediaItemIndex

    The index at which to add the MediaItem.

    Remarks

    Note that altering the Playlist on runtime can cause unexpected behavior. It is safer to create a new Playlist instead.

    | Edit this page View Source

    AddPlaylist(Playlist, Action)

    Add a new Playlist to the list of playlists.

    Declaration
    public static void AddPlaylist(Playlist playlist, Action onPlaylistLoaded)
    Parameters
    Type Name Description
    Playlist playlist

    The Playlist to add.

    Action onPlaylistLoaded

    The action to perform when the playlist is loaded.

    | Edit this page View Source

    AddPlaylist(Playlist, bool, int, float)

    Add a new Playlist to the list of playlists.

    Declaration
    public static void AddPlaylist(Playlist playlist, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    Playlist playlist

    The Playlist to add.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    AddPlaylist(Playlist, int, float)

    Add a new Playlist to the list of playlists.

    Declaration
    public static void AddPlaylist(Playlist playlist, int startMediaItemIndex, float startPosition = 0)
    Parameters
    Type Name Description
    Playlist playlist

    The Playlist to add.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    ClearPlaylist()

    Clears MediaItems from the current Playlist.

    Declaration
    public static void ClearPlaylist()
    Remarks

    Note that altering the Playlist on runtime can cause unexpected behavior. It is safer to create a new Playlist instead.

    | Edit this page View Source

    FadeIn(float)

    Fades in the current MediaItem over a specified duration. (in seconds)

    Declaration
    public static void FadeIn(float duration)
    Parameters
    Type Name Description
    float duration

    The duration of the fade-in effect.

    | Edit this page View Source

    FadeOut(float)

    Fades out the current MediaItem over a specified duration. (in seconds)

    Declaration
    public static void FadeOut(float duration)
    Parameters
    Type Name Description
    float duration

    The duration of the fade-out effect.

    | Edit this page View Source

    FastForward()

    Fast-forwards the current MediaItem by SeekIncrement.

    Declaration
    public static void FastForward()
    | Edit this page View Source

    GetCurrentPosition()

    Gets the current playback position of the MediaItem.

    Declaration
    public static float GetCurrentPosition()
    Returns
    Type Description
    float

    The current playback position.

    | Edit this page View Source

    GetDuration()

    Gets the duration of the current MediaItem.

    Declaration
    public static float GetDuration()
    Returns
    Type Description
    float

    The duration of the current MediaItem.

    | Edit this page View Source

    GetMediaItem(int, int)

    Gets a media item by its index and optional playlist index.

    Declaration
    public static MediaItem GetMediaItem(int mediaItemIndex, int playlistIndex = -1)
    Parameters
    Type Name Description
    int mediaItemIndex

    The index of the media item to get.

    int playlistIndex

    The index of the playlist to get the media item from. If -1, uses the current playlist index.

    Returns
    Type Description
    MediaItem

    The media item if found; otherwise, null.

    | Edit this page View Source

    GetNativePlayerName()

    Declaration
    public static string GetNativePlayerName()
    Returns
    Type Description
    string
    | Edit this page View Source

    GetPlaylist(int)

    Gets a playlist by its index.

    Declaration
    public static Playlist GetPlaylist(int playlistIndex)
    Parameters
    Type Name Description
    int playlistIndex

    The index of the playlist to get.

    Returns
    Type Description
    Playlist

    The playlist if found; otherwise, null.

    | Edit this page View Source

    GetShuffleOrder()

    Gets the shuffle order of the current Playlist.

    Declaration
    public static int[] GetShuffleOrder()
    Returns
    Type Description
    int[]

    An array representing the shuffle order.

    | Edit this page View Source

    Initialize(MediaItem, bool, float)

    Initialize the Glitch9.NativeMediaPlayer plugin with a MediaItem.

    Declaration
    public static void Initialize(MediaItem mediaItem, bool playWhenReady = false, float startPosition = 0)
    Parameters
    Type Name Description
    MediaItem mediaItem

    The MediaItem to initialize the plugin with.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    float startPosition

    The position to start playback from.

    Remarks

    Use this only when NativeMediaPlayerSettings.AutoInit is set to false, and you are initializing the NativeMediaPlayer plugin manually. You also have to initialize AndroidSettings and iOSSettings manually.

    | Edit this page View Source

    Initialize(Playlist, bool, int, float)

    Initialize the Glitch9.NativeMediaPlayer plugin with a Playlist.

    Declaration
    public static void Initialize(Playlist playlist, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    Playlist playlist

    The Playlist to initialize the plugin with.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    Remarks

    Use this only when NativeMediaPlayerSettings.AutoInit is set to false, and you are initializing the NativeMediaPlayer plugin manually. You also have to initialize AndroidSettings and iOSSettings manually.

    | Edit this page View Source

    Initialize(IEnumerable<Playlist>, bool, int, int, float)

    Initialize the Glitch9.NativeMediaPlayer plugin with multiple Playlists.

    Declaration
    public static void Initialize(IEnumerable<Playlist> playlists, bool playWhenReady = false, int startMediaItemIndex = 0, int startPlaylistIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    IEnumerable<Playlist> playlists

    The list of Playlists to initialize the plugin with.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    int startPlaylistIndex

    The index of the Playlist to start playback from.

    float startPosition

    The position to start playback from.

    Remarks

    Use this only when NativeMediaPlayerSettings.AutoInit is set to false, and you are initializing the NativeMediaPlayer plugin manually. You also have to initialize AndroidSettings and iOSSettings manually.

    | Edit this page View Source

    Next()

    Skips to the next MediaItem.

    Declaration
    public static void Next()
    | Edit this page View Source

    OnApplicationPause(bool)

    Declaration
    public static void OnApplicationPause(bool pause)
    Parameters
    Type Name Description
    bool pause
    | Edit this page View Source

    OnApplicationQuit()

    Declaration
    public static void OnApplicationQuit()
    | Edit this page View Source

    Pause()

    Pauses media playback of the current MediaItem.

    Declaration
    public static void Pause()
    | Edit this page View Source

    Play()

    Play the current MediaItem. Please make sure that everything is set up correctly before calling this method.

    Declaration
    public static void Play()
    | Edit this page View Source

    Play(MediaItem)

    Plays a MediaItem from the current Playlist. If the MediaItem is not in the Playlist, it will be added.

    Declaration
    public static void Play(MediaItem mediaItem)
    Parameters
    Type Name Description
    MediaItem mediaItem

    The MediaItem to play.

    | Edit this page View Source

    Play(int, float)

    Play the current MediaItem at the specified index and the position. Please make sure that everything is set up correctly before calling this method.

    Declaration
    public static void Play(int mediaItemIndex, float startingPosition = 0)
    Parameters
    Type Name Description
    int mediaItemIndex

    The index of the MediaItem to play.

    float startingPosition

    The position to start playback from.

    | Edit this page View Source

    PlayUrl(string)

    Plays a MediaItem from the current Playlist using a remote URL. If the MediaItem is not in the Playlist, it will be added.

    Declaration
    public static void PlayUrl(string fileUrl)
    Parameters
    Type Name Description
    string fileUrl

    The remote URL of the MediaItem to play.

    | Edit this page View Source

    Previous()

    Skips to the previous MediaItem.

    Declaration
    public static void Previous()
    | Edit this page View Source

    Release()

    [CAUTION] Use this method very carefully. It will release all native audio player instances, and it won't be recoverable. You have to reinitialize the player to use it again.

    Declaration
    public static void Release()
    | Edit this page View Source

    RemoveMediaItem(int)

    Removes a MediaItem from the current Playlist.

    Declaration
    public static void RemoveMediaItem(int mediaItemIndex)
    Parameters
    Type Name Description
    int mediaItemIndex

    The index of the MediaItem to remove.

    Remarks

    Note that altering the Playlist on runtime can cause unexpected behavior. It is safer to create a new Playlist instead.

    | Edit this page View Source

    RemovePlaylist(int)

    Remove a Playlist from the list of playlists. Note: Removing the current playlist will stop playback.

    Declaration
    public static void RemovePlaylist(int index)
    Parameters
    Type Name Description
    int index

    The index of the Playlist to remove.

    | Edit this page View Source

    Rewind()

    Rewinds the current MediaItem by SeekIncrement.

    Declaration
    public static void Rewind()
    | Edit this page View Source

    SeekTo(float)

    Seeks to a specific time in the current MediaItem.

    Declaration
    public static void SeekTo(float time)
    Parameters
    Type Name Description
    float time

    The time to seek to.

    | Edit this page View Source

    SelectPlaylist(int)

    Change the current Playlist to the one at the specified index.

    Declaration
    public static void SelectPlaylist(int playlistIndex)
    Parameters
    Type Name Description
    int playlistIndex

    The index of the Playlist to change to.

    | Edit this page View Source

    SelectPlaylist(int, bool, int, float)

    Change the current Playlist to the one at the specified index.

    Declaration
    public static void SelectPlaylist(int playlistIndex, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    int playlistIndex

    The index of the Playlist to change to.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    SelectPlaylist(int, int, float)

    Change the current Playlist to the one at the specified index.

    Declaration
    public static void SelectPlaylist(int playlistIndex, int startMediaItemIndex, float startPosition = 0)
    Parameters
    Type Name Description
    int playlistIndex

    The index of the Playlist to change to.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    SetMediaItem(MediaItem, bool, int, float)

    Set the current MediaItem to the specified MediaItem.

    Declaration
    public static void SetMediaItem(MediaItem mediaItem, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    MediaItem mediaItem

    The MediaItem to set.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    SetMediaItem(MediaItem, int, bool, int, float)

    Replaces the current playlist with the new playlist.

    Declaration
    public static void SetMediaItem(MediaItem mediaItem, int playlistIndex, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    MediaItem mediaItem

    The MediaItem to set.

    int playlistIndex

    The index of the Playlist to set the MediaItem to.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    SetPlaybackSpeed(float)

    Alters the playback speed of the native player. It will be automatically reset to 1.0 when a new media item is played.

    Declaration
    public static void SetPlaybackSpeed(float speed)
    Parameters
    Type Name Description
    float speed

    The playback speed to set.

    | Edit this page View Source

    SetPlaylist(Playlist, bool, int, float)

    Replaces the current playlist with the new playlist.

    Declaration
    public static void SetPlaylist(Playlist playlist, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    Playlist playlist

    The Playlist to set.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    SetPlaylist(Playlist, int, bool, int, float)

    Replaces the playlist at the specified index with the new playlist.

    Declaration
    public static void SetPlaylist(Playlist playlist, int playlistIndex, bool playWhenReady = false, int startMediaItemIndex = 0, float startPosition = 0)
    Parameters
    Type Name Description
    Playlist playlist

    The Playlist to Set.

    int playlistIndex

    The index of the Playlist to replace.

    bool playWhenReady

    Whether to start playback when the plugin is initialized.

    int startMediaItemIndex

    The index of the MediaItem to start playback from.

    float startPosition

    The position to start playback from.

    | Edit this page View Source

    Stop()

    Stops media playback of the current MediaItem.

    Declaration
    public static void Stop()
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX