Playlist

The Playlist class represents a collection of media items, along with associated metadata such as the album title, album artist, and download directory. Below is a detailed reference for each property and method available in the Playlist class.

Constructors

Playlist

  • Description: Initializes a new instance of the Playlist class.

  • Parameters:

    • List<MediaItem> mediaItems (optional): The list of media items in the playlist.

    • string albumTitle (optional): The title of the album.

    • string albumArtist (optional): The artist of the album.

  • Usage:

    Playlist playlist = new Playlist(new List<MediaItem>(), "Album Title", "Album Artist");

Properties

Index

  • Description: Gets or sets the index of the playlist.

  • Remarks: This is automatically set when the playlist is added to the MediaPlayer.

  • Type: int

  • Usage:

    int index = playlist.Index;
    playlist.Index = 1;

UriType

  • Description: Gets or sets the type of URI that the playlist contains.

  • Remarks: Once this information is passed to the native plugin, changes to this value will not be reflected.

  • Type: UriType

  • Usage:

    UriType uriType = playlist.UriType;
    playlist.UriType = UriType.RemoteURL;

DownloadDirectory

  • Description: Gets or sets the directory where the media files will be downloaded to.

  • Remarks: Once this information is passed to the native plugin, changes to this value will not be reflected.

  • Type: string

  • Usage:

    string directory = playlist.DownloadDirectory;
    playlist.DownloadDirectory = "/path/to/download";

AlbumTitle

  • Description: Gets or sets the title of the album.

  • Remarks: Once this information is passed to the native plugin, changes to this value will not be reflected.

  • Type: string

  • Usage:

    string albumTitle = playlist.AlbumTitle;
    playlist.AlbumTitle = "New Album Title";

AlbumArtist

  • Description: Gets or sets the artist of the album.

  • Remarks: Once this information is passed to the native plugin, changes to this value will not be reflected.

  • Type: string

  • Usage:

    string albumArtist = playlist.AlbumArtist;
    playlist.AlbumArtist = "New Album Artist";

Count

  • Description: Gets the number of media items in the playlist.

  • Type: int

  • Usage:

    int count = playlist.Count;

MediaItems

  • Description: Gets the list of media items in the playlist.

  • Type: List<MediaItem>

  • Usage:

    List<MediaItem> items = playlist.MediaItems;

SerializedPlaylist

  • Description: Gets or sets the serialized representation of the playlist.

  • Type: string

  • Usage:

    string serialized = playlist.SerializedPlaylist;
    playlist.SerializedPlaylist = "serialized_data";

Methods

AddEmptyMediaItem

  • Description: Adds an empty media item to the playlist.

  • Usage:

    playlist.AddEmptyMediaItem();

Contains

  • Description: Checks if the playlist contains a specific media item.

  • Parameters:

    • MediaItem mediaItem: The media item to check.

  • Returns: bool

  • Usage:

    bool contains = playlist.Contains(mediaItem);

GetIndex

  • Description: Gets the index of a specific media item in the playlist.

  • Parameters:

    • MediaItem mediaItem: The media item to find.

  • Returns: int

  • Usage:

    int index = playlist.GetIndex(mediaItem);

AddMediaItem

  • Description: Adds a media item to the playlist.

  • Parameters:

    • MediaItem item: The media item to add.

  • Usage:

    playlist.AddMediaItem(mediaItem);

SetMediaItem

  • Description: Replaces a media item in the playlist at a specified index.

  • Parameters:

    • int index: The index at which to replace the media item.

    • MediaItem item: The new media item.

  • Usage:

    playlist.SetMediaItem(0, mediaItem);

RemoveMediaItem

  • Description: Removes a media item from the playlist at a specified index.

  • Parameters:

    • int index: The index of the media item to remove.

  • Usage:

    playlist.RemoveMediaItem(0);

SetMediaItems

  • Description: Replaces the current list of media items with a new list.

  • Parameters:

    • List<MediaItem> newMediaItems: The new list of media items.

  • Usage:

    playlist.SetMediaItems(new List<MediaItem>());

ClearMediaItems

  • Description: Clears the list of media items.

  • Usage:

    playlist.ClearMediaItems();

ReassureMediaItems

  • Description: Ensures that all media items in the playlist have the correct playlist index, media item index, and download directory.

  • Usage:

    playlist.ReassureMediaItems();

Example Usage

Here's an example of how you might use the Playlist class in your application:

using Glitch9.NativePlugins.NativeMediaPlayer;
using UnityEngine;

public class PlaylistExample : MonoBehaviour
{
    void Start()
    {
        Playlist playlist = new Playlist(new List<MediaItem>(), "Example Album", "Example Artist");
        MediaItem item = new MediaItem(UriType.RemoteURL, "http://example.com/media.mp3");
        playlist.AddMediaItem(item);

        Debug.Log($"Playing playlist: {playlist.AlbumTitle} by {playlist.AlbumArtist}");
    }
}

This API reference provides detailed information on each property and method available in the Playlist class, along with their usage examples. This should help users understand and utilize the features of your media player effectively.

Last updated