![]() |
![]() |
![]() |
MAFW Manual | ![]() |
---|
Another important use case of a source is to provide metadata about particular media. This can be achieved using mafw_source_get_metadata like this:
static void metadata_cb(MafwSource *source, const gchar *objectid, GHashTable *metadata, gpointer user_data, const GError *error) { if (error != NULL) { g_print("Error %d: %s\n", error->code, error->message); } else { gchar *title, *artist, *album, *mime; if (metadata) { GValue *v; v = mafw_metadata_first(metadata, MAFW_METADATA_KEY_TITLE); title = v ? g_value_get_string(v) : "Unknown"; v = mafw_metadata_first(metadata, MAFW_METADATA_KEY_ARTIST); artist = v ? g_value_get_string(v) : "Unknown"; v = mafw_metadata_first(metadata, MAFW_METADATA_KEY_ALBUM); album = v ? g_value_get_string(v) : "Unknown"; v = mafw_metadata_first(metadata, MAFW_METADATA_KEY_MIME); mime = v ? g_value_get_string(v) : "Unknown"; } else { title = "Unknown"; artist = "Unknown"; album = "Unknown"; mime = "Unknown"; } g_print(" Title: %s\n", title); g_print("Artist: %s\n", artist); g_print(" Album: %s\n", album); g_print(" Mime: %s\n", mime); } } static void metadata_example (MafwSource *source, gchar *objectid) { const gchar *const *keys; keys = MAFW_SOURCE_LIST( MAFW_METADATA_KEY_MIME, MAFW_METADATA_KEY_ARTIST, MAFW_METADATA_KEY_ALBUM, MAFW_METADATA_KEY_TITLE); mafw_source_get_metadata( source, /* The source object */ objectid, /* The media resource we want metadata from */ keys, /* The metadata we are interested in */ metadata_cb, /* Callback */ NULL); /* User data for Callback */ }
The example queries metadata for a particular object ID (which should be valid for the source being queried, returned by a previous browse operation). The parameters passed to mafw_source_get_metadata are:
Source
, the MafwSource to be queried.
Object ID
, the object ID to get metadata from.
Keys
, metadata information we are interested in.
Callback
, the callback used to get the results.
User data
, the user data for the callback.
The result of the metadata operation is returned using the callback provided. The parameters passed to the callback function are:
Source
, the MafwSource that produced the result.
Object ID
, the object ID the metadata comes from.
Metadata
, the metadata values.
User data
, the user data for the callback.
Error
, a GError that, if set, informs of an
error in the metadata retrieval operation.
This callback should be called only once.