UI Implementations

NativeMediaPlayer offers easy UI implementations with pre-coded scripts with easy-to-use custom inspectors. Create an empty object in Unity hierarchy and add component to find one of the UI scripts outlined below.

 

  • Media Button makes it easy to create your own media button such as play, pause, stop, loop, shuffle and more
  • Volume Bar makes it easy to create your own volume bar
  • Seek Bar makes it easy to create your own seek bar
  • UI Settings manages shared properties that apply to all UI elements listed above

 

Media Button

 

Media Button is an All-In-One component that can create all buttons that NativeMediaPlayer currently supports like the image below.

 

Media Button can become one of the many buttons

Choose Button Type to determine which button it is, and put in the necessary components such as Image and Events. Button colors are defined with UI Settings, and check Dark Mode if you want to use the Dark Mode colors.

 

Volume Bar

 

To create a volume bar, create a Unity built-in slider and put that into Volume Bar. The slider will behave as volume bar of the NativeMediaPlayer. In case you need events, add the events to the slider.

 

 

Seek Bar

 

Seek Bar also needs a Unity built-in slider. Create a slider and put it into Seek Bar. The slider will behave as seek bar of the NativeMediaPlayer. Update Interval is how often seek bar will be updated, and the default value is 0.5f which means that it will be updated every 0.5 seconds. You can add texts that will display the current position and the duration of the current media item.

 

 

 

 

UI Settings

 

UI Settings manages all shared properties of NativeMediaPlayer UI elements. It only manages UI colors in the current version.

 

Playlist

Playlist is a basic media source type that manages multiple media items for NativeMediaPlayer. It can only have one UriType which determines which native player the plugin is going to use, and pass the media data to the corresponding player. To add a new MediaItem to Playlist, simply click on the 'Add a new media item' button in the inspector menu.

 

If you are using StreamingAssets, drag the file directly into the box under 'Put in a file from StreamingAssets folder below'. The inspector will automatically detect the filename and use it as MediaUri of the media item. If you are using RemoteUrl, the box becomes a textbox where you can enter the URL.

 

NativeMediaPlayer will try to retrieve the media metadata using native APIs by the default, but you can also choose to customize media metadata and prevent from triggering those native APIs. Choosing custom media metadata will expand the inspector menu and show editable property fields of each metadata.

 

Expanded with custom metadata fields

Modifying the playlist

 

It’s possible to dynamically modify a playlist by adding, and removing media items. This can be done both before and during playback by calling the corresponding playlist API methods:

// Adds a media item at position 1 in the playlist.
playlist.AddMediaItem(1, new MediaItem(uriType, mediaUri));

// Removes the first item from the playlist.

playlist.RemoveMediaItem(0);
 
Replacing and clearing the entire playlist are also supported:
// Replaces the playlist with a new one.
List<MediaItem> newItems = new List<MediaItem>();
UriType uriType = playlist.Type;
newItems.Add(new MediaItem(uriType, mediaUri1));
newItems.Add(new MediaItem(uriType, mediaUri2));
playlist.SetMediaItems(newItems);

// Clears the playlist.
playlist.ClearMediaItems();

 

Querying the media items

 

Media items contained in a playlist can be individually queried using playlist.MediaItem[id].

// Quering title of the first item from the playlist.
string title = playlist.MediaItem[0].Title;

 

Methods

 

using NativeMediaPlayerCenter;

Playlist Playlist(int id,  UriType path, List<MediaItem> mediaItems = null, string title = null, string artist = null) Build a new Playlist
void AddMediaItem(MediaItem item = null) Add an empty MediaItem
void AddMediaItem(int index, MediaItem item) Add a MediaItem
void RemoveMediaItem(int index) Remove a MediaItem
void Sync() Send the Playlist to the native side, so that it can be readible from the native plugin. Use this fuction before preparing the native player.

 

Parameters

int Id Index number of the Playlist.
UriType Path An enum value that indicates where your sources are located.

short UriType.StreamingAssets = 0
short UriType.RemoteURL = 1
string Title Title of the Playlist.
void Artist Artist of the Playlist.
List<MediaItem> MediaItems MediaItems in the Playlist.
int Count Total number of the MediaItems.

 

MediaEventListener

MediaEventListener receives native callbacks. A game object with MediaEventListener.cs must be in the scene for the plugin to work properly. The chart below explains how the callbacks work in order.

 

 

NativeMediaPlayer player events

 

Namespace

 

using NativeMediaPlayerCenter;

 

Listeners

callback OnInit Called when NativeMediaPlayer plugin is initiated
callback OnReady Called when a new Playlist and its metadatas are fully registered to the native side
callback OnPrepared Called when player is able to immediately play a MediaItem
callback OnComplete Called when player finishes playing a MediaItem
callback OnError Called when error occurs
callback OnIsPlayingChanged(True) Called when player starts/resumes playing
callback OnIsPlayingChanged(False) Called when player stops/pauses playing
callback OnIsLoadingChanged(True) Called when player starts loading a MediaItem
callback OnIsLoadingChanged(False) Called when player finishes loading a MediaItem
callback OnIsBufferingChanged(True) Called when player starts buffering a MediaItem during playback
callback OnIsBufferingChanged(False) Called when player finished buffering a MediaItem during playback

 

Methods

void AddOnInitListener(UnityAction action) Add an action to OnInit
void AddOnReadyListener(UnityAction action) Add an action to OnReady
void AddOnPreparedListener(UnityAction action) Add an action to OnPrepared
void AddOnCompleteListener(UnityAction action) Add an action to OnComplete
void AddOnIsPlayingChangedListener(bool isPlaying, UnityAction action) Add an action to OnIsPlayingChanged
void AddOnIsLoadingChangedListener(bool isLoading, UnityAction action) Add an action to OnIsLoadingChanged
void AddOnIsBufferingChangedListener(bool isBuffering, UnityAction action) Add an action to OnIsBufferingChanged