The Playkit SDK provides a convenient method for retrieving metadata from HLS and DASH sources. The following article explains how to retrieve the metadata and provides a list of all available metadata types. You can also find a working code sample here.

Retrieving Metadata

There are three steps required for retrieving the metadata:

  1. Subscribe to the METADATA_AVAILABLE event.
  2. Obtain the Metadata object.
  3. Get the metadata.

Subscribing to the METADATE_AVAILABLE Event

You will need to subscribe to the corresponding event called METADATA_AVAILABLE. We recommend reading this article on event subscriptions for more information.

player.addEventListener(new PKEvent.Listener() {
    @Override
    public void onEvent(PKEvent event) {
				//Obtain the Metadata object.
    }
    //Subscribe to the events you are interested in.
}, PlayerEvent.Type.METADATA_AVAILABLE);

Obtaining the Metadata Object

The METADATA_AVAILABLE event holds data objects with Metadata. To get this object, you’ll first need to cast the event to PlayerEvent.MetadataAvailable, and then apply a getter to it.

//Cast received event to MetadataAvailable event, which holds the data object with actual metadata.
PlayerEvent.MetadataAvailable metadataAvailableEvent = (PlayerEvent.MetadataAvailable) event;

//Retrieve the metadata object itself.
Metadata metadata = metadataAvailableEvent.getMetadata();

Getting the Metadata

Each media entry can have more than one type of metadata object, which are called frames. To receive the frame you are interested in, you’ll need to review all the entries in the Metadata object to locate the relevant instance. In the next section, you’ll find a list of all available types of metadata. Use the following code to get the metadata you need.

//Iterate through all entries in metadata object.
for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry metadataEntry = metadata.get(i);

    //For simplicity, in this example, we are interested only in TextInformationFrame.
    if (metadataEntry instanceof TextInformationFrame) {

	//Cast mediaEntry to TextInformationFrame.
	TextInformationFrame textInformationFrame = (TextInformationFrame) metadataEntry;

	//Print to log.
	Log.d(TAG, "metadata text information: " + textInformationFrame.value);
    }
}

Available Metadata Types

HLS

DASH

Have Questions or Need Help?

Check out the Kaltura Player SDK Forum page for different ways of getting in touch.