Playlist

Playlist is a basic media source type that manages multiple media items. 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.

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.

Creating a playlist at runtime

Playlist can be dynamically created anytime at runtime.

// Create a playlist 
Playlist playlist = new Playlist(UriType.RemoteURL);

// Add a new media item with a URL
MediaItem mediaItem = new MediaItem(UriType.RemoteURL, "https://somewebsite.com/filename.mp3"));
playlist.AddMediaItem(mediaItem);

Modifying playlist at runtime

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 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;

API reference

pagePlaylist

Last updated