> For the complete documentation index, see [llms.txt](https://glitch9.gitbook.io/native-media-player/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://glitch9.gitbook.io/native-media-player/legacy-docs/legacy-api-references/playlist.md).

# 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**:

  <pre class="language-csharp"><code class="lang-csharp"><strong>Playlist playlist = new Playlist(new List&#x3C;MediaItem>(), "Album Title", "Album Artist");
  </strong></code></pre>

### 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**:

  ```csharp
  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**:

  ```csharp
  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**:

  ```csharp
  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**:

  ```csharp
  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**:

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

#### Count

* **Description**: Gets the number of media items in the playlist.
* **Type**: `int`
* **Usage**:

  ```csharp
  int count = playlist.Count;
  ```

#### MediaItems

* **Description**: Gets the list of media items in the playlist.
* **Type**: `List<MediaItem>`
* **Usage**:

  ```csharp
  List<MediaItem> items = playlist.MediaItems;
  ```

#### SerializedPlaylist

* **Description**: Gets or sets the serialized representation of the playlist.
* **Type**: `string`
* **Usage**:

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

### Methods

#### AddEmptyMediaItem

* **Description**: Adds an empty media item to the playlist.
* **Usage**:

  ```csharp
  playlist.AddEmptyMediaItem();
  ```

#### Contains

* **Description**: Checks if the playlist contains a specific media item.
* **Parameters**:
  * `MediaItem mediaItem`: The media item to check.
* **Returns**: `bool`
* **Usage**:

  ```csharp
  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**:

  ```csharp
  int index = playlist.GetIndex(mediaItem);
  ```

#### AddMediaItem

* **Description**: Adds a media item to the playlist.
* **Parameters**:
  * `MediaItem item`: The media item to add.
* **Usage**:

  ```csharp
  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**:

  ```csharp
  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**:

  ```csharp
  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**:

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

#### ClearMediaItems

* **Description**: Clears the list of media items.
* **Usage**:

  ```csharp
  playlist.ClearMediaItems();
  ```

#### ReassureMediaItems

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

  ```csharp
  playlist.ReassureMediaItems();
  ```

### Example Usage

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

```csharp
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.
