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.
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);
// 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. |