Media Metadata

The MediaMetadata is designed to store detailed information about a media item. This includes various attributes that describe the media content, such as title, artist, album, artwork, genre, and release date.

Basic Properties:

  1. Album: The album name of the media item.

  2. AlbumArtist: The artist of the album.

  3. Title: The title of the media item.

  4. Artwork: The artwork associated with the media item, typically an album cover or thumbnail image.

  5. Artist: The artist of the media item.

  6. Genre: The genre of the media item.

  7. ReleaseDate: The release date of the media item.

Usage Example

Here’s a simple example of how you might create and use a MediaMetadata instance:

using Glitch9.NativePlugins.NativeMediaPlayer;
using UnityEngine;

public class MediaExample : MonoBehaviour
{
    void Start()
    {
        // Create artwork from a sprite
        Sprite sprite = Resources.Load<Sprite>("path_to_sprite");
        Artwork artwork = sprite;

        // Create media metadata
        MediaMetadata metadata = new MediaMetadata
        {
            Album = "Greatest Hits",
            AlbumArtist = "Famous Artist",
            Title = "Hit Song",
            Artwork = artwork,
            Artist = "Famous Artist",
            Genre = "Pop",
            ReleaseDate = "2023-06-25"
        };

        // Use the metadata
        Debug.Log($"Title: {metadata.Title}, Artist: {metadata.Artist}");
    }
}

Metadata Retrieval

Depending on the MetadataType, metadata can either be custom-defined or retrieved dynamically at runtime.

MetadataType Options

  1. Retrieve:

    • Description: This type indicates that metadata should be retrieved dynamically at runtime. The system will attempt to fetch the metadata from the media file or a remote source.

    • Usage: Use this type when you want the media player to automatically gather information such as title, artist, album, and other details directly from the media file. This is useful for media files where metadata might change or is not predefined.

    • Example:

      mediaItem.MetadataType = MetadataType.Retrieve;
  2. Custom:

    • Description: This type indicates that custom metadata has been defined and should be used. The metadata is set manually, often through the Unity inspector.

    • Usage: Use this type when you have specific, predefined information about the media item that you want to ensure is used. This is useful for cases where the metadata is known in advance and should not change.

    • Example:

      mediaItem.MetadataType = MetadataType.Custom;

How Media Metadata works

Below diagram illustrates the workflow for retrieving metadata for media items within the Unity Native Media Player plugin. The operations are divided between the Unity side (black) and the native side (green).

  1. Get Metadata (MediaItem): The process begins with a request to get metadata for a media item.

  2. Custom Metadata Check: The system checks if custom metadata exists.

    • If Yes: The custom metadata is returned.

    • If No: An error is thrown, and fallback metadata is returned.

  3. Retrieve Metadata: If the metadata type is set to "Retrieved," the process moves to the native side.

  4. Native Plugin Bridge: The request is passed through the native plugin bridge to the native metadata retriever.

  5. Metadata Retriever (Native): The native side attempts to retrieve the metadata.

  6. Retrieval Result: The result of the metadata retrieval is checked.

    • If Successful: The retrieved metadata is sent back to Unity.

    • If Failed: An error is thrown, and fallback metadata is used.

  7. Title Check: Once the metadata is received, the system checks if the title is null or empty.

    • If Title is Empty: The filename is used as the title.

    • If Title is Not Empty: The metadata is successfully returned to Unity.

This workflow ensures that metadata is properly managed and retrieved, providing a robust system for handling media information in the Unity Native Media Player plugin.

Last updated