MAFW Manual |
---|
Developers traverse a playlist and obtain the object identifier of each individual item contained in it like this:
{ size = mafw_playlist_get_size (playlist, &error); if (error != NULL) { /* Error management */ } for (i = 0; i < size; i++) { gchar *oid = mafw_playlist_get_item (playlist, i, &error); if (error != NULL) { /* Error management */ } /* Information treatment */ } }
In order to obtain information other than the object identifier, the asynchronous API must be used.
In this case, mafw_playlist_get_items_md should be used, which allows to obtain metadata for the entries enclosed in a particular range of the playlist. The example shows how to retrieve metadata for all the elements in a playlist:
{ size = mafw_playlist_get_size (playlist, &error); if (error != NULL) { /* Error management */ } mafw_playlist_get_items_md (playlist, 0, size - 1, MAFW_SOURCE_LIST (MAFW_METADATA_KEY_TITLE), playlist_get_items_md_cb, NULL, NULL); } static void playlist_get_items_md_cb(MafwPlaylist *playlist, guint index, const gchar *object_id, GHashTable *metadata, gpointer userdata) { GError* error = NULL; GValue* value; const gchar* title; value = mafw_metadata_first (metadata, MAFW_METADATA_KEY_TITLE); title = g_value_get_string (value); /* Probably show this title string in the UI */ }
The callback is invoked once per entry and is passed a hash table
with metadata associated to media resource associated to the object
identifier specified by object_id
. This hash table may
contain metadata with multiple values for each metadata key and this
is why MAFW provides mafw_metadata_first to access the first (or only)
value in the hash table for a particular metadata key. In order to obtain
all the values for a particular metadata key, the developer can use
the normal hash table API. In this case, if there is only one value for
that metadata key, the hash table will return a GValue holding the value.
If it is multi-valued, it will return a GValueArray. Take a look at
the Mafw API reference for more info.