> 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/mediaitem.md).

# MediaItem

The `MediaItem` class represents a single media item in a playlist and includes metadata and state information about the media. Below is a detailed reference for each property and method available in the `MediaItem` class.

### Constructors

#### MediaItem

* **Description**: Initializes a new instance of the `MediaItem` class.
* **Parameters**:
  * `UriType type`: The type of URI.
  * `string uri`: The URI of the media item.
  * `MediaMetadata metadata` (optional): Metadata associated with the media item.
* **Usage**:

  ```csharp
  MediaItem item = new MediaItem(UriType.RemoteURL, "http://example.com/media.mp3");
  ```

### Properties

#### Index

* **Description**: Gets or sets the index of the media item in the playlist.
* **Type**: `int`
* **Usage**:

  ```csharp
  int index = item.Index;
  item.Index = 1;
  ```

#### PlaylistIndex

* **Description**: Gets or sets the index of the playlist to which this media item belongs.
* **Type**: `int`
* **Usage**:

  ```csharp
  int playlistIndex = item.PlaylistIndex;
  item.PlaylistIndex = 0;
  ```

#### MetadataState

* **Description**: Gets or sets the state of the metadata retrieval process.
* **Type**: `MetadataState`
* **Usage**:

  ```csharp
  MetadataState state = item.MetadataState;
  ```

#### DownloadDirectory

* **Description**: Gets or sets the download directory for the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string directory = item.DownloadDirectory;
  item.DownloadDirectory = "/path/to/download";
  ```

#### MetadataType

* **Description**: Gets or sets the type of metadata retrieval.
* **Type**: `MetadataType`
* **Usage**:

  ```csharp
  MetadataType type = item.MetadataType;
  item.MetadataType = MetadataType.Custom;
  ```

#### Metadata

* **Description**: Gets or sets the metadata of the media item.
* **Type**: `MediaMetadata`
* **Usage**:

  ```csharp
  MediaMetadata metadata = item.Metadata;
  item.Metadata = new MediaMetadata { Title = "New Title" };
  ```

#### Uri

* **Description**: Gets the URI of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string uri = item.Uri;
  ```

#### UriType

* **Description**: Gets the URI type of the media item.
* **Type**: `UriType`
* **Usage**:

  ```csharp
  UriType uriType = item.UriType;
  ```

#### Title

* **Description**: Gets the title of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string title = item.Title;
  ```

#### Artist

* **Description**: Gets the artist of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string artist = item.Artist;
  ```

#### Genre

* **Description**: Gets the genre of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string genre = item.Genre;
  ```

#### ReleaseDate

* **Description**: Gets the release date of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string releaseDate = item.ReleaseDate;
  ```

#### AlbumTitle

* **Description**: Gets the album title of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string albumTitle = item.AlbumTitle;
  ```

#### AlbumArtist

* **Description**: Gets the album artist of the media item.
* **Type**: `string`
* **Usage**:

  ```csharp
  string albumArtist = item.AlbumArtist;
  ```

#### Artwork

* **Description**: Gets the artwork of the media item.
* **Type**: `Artwork`
* **Usage**:

  ```csharp
  Artwork artwork = item.Artwork;
  ```

#### SerializedMediaItem

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

  ```csharp
  string serialized = item.SerializedMediaItem;
  item.SerializedMediaItem = "serialized_data";
  ```

### Methods

#### RetrieveMetadata

* **Description**: Retrieves the metadata for the media item.
* **Usage**:

  ```csharp
  item.RetrieveMetadata();
  ```

#### SetMetadata

* **Description**: Sets the metadata for the media item.
* **Parameters**:
  * `MediaMetadata metadata`: The metadata to set.
* **Usage**:

  ```csharp
  item.SetMetadata(new MediaMetadata { Title = "New Title" });
  ```

#### MetadataWarning

* **Description**: Logs a warning if metadata is not retrieved yet.
* **Usage**:

  ```csharp
  string warning = item.MetadataWarning();
  ```

### Example Usage

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

```csharp
using Glitch9.NativePlugins.NativeMediaPlayer;
using UnityEngine;

public class MediaItemExample : MonoBehaviour
{
    void Start()
    {
        MediaItem item = new MediaItem(UriType.RemoteURL, "http://example.com/media.mp3");
        item.Metadata = new MediaMetadata { Title = "Example Title", Artist = "Example Artist" };

        Debug.Log($"Playing media: {item.Title} by {item.Artist}");
    }
}
```
