Creating Playlist at Runtime
Last updated
Last updated
Creating a new playlist at runtime with the MediaPlayer
class is straightforward. This guide will walk you through the process step-by-step.
Before creating a playlist, you need to decide where your media files are located. The UriType
enum in the MediaPlayer
class helps you specify the source of your media files. Here are the available options:
UriType
OptionsStreamingAssets: The media file is located in the StreamingAssets folder.
Android uses '' to play the media file.
iOS uses '' to play the media file.
RemoteURL: The media file is located at a remote URL (e.g., ).
Android uses '' to play the media file.
iOS uses '' to play the media file.
DownloadAndPlay: The media file will be downloaded to the 'PersistentDataPath' before playing.
Android uses '' to play the media file.
iOS uses '' to play the media file.
PersistentDataPath: The media file is located in the 'PersistentDataPath'.
Android uses '' to play the media file.
iOS uses '' to play the media file.
First, you need to create MediaItem
objects that will be part of your playlist. Each MediaItem
represents a piece of media that you want to add to your playlist.
Example:
Once you have your MediaItem
objects, you can create a Playlist
object and add these items to it.
Example:
If you want to add a new playlist to your existing list of playlists, you can use the AddPlaylist
method.
Example:
Or you can replace the current playlist with SetPlaylist
method.
Example:
Here's a complete example of how to create a new playlist and add it to the MediaPlayer
: