×
Namespaces

Variants
Actions

Monitoring volume level in Maemo 5 using MAFW

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata
Article
Created: divanov (19 Mar 2010)
Last edited: lpvalente (20 Apr 2013)

This article presents a code snippet to monitor volume level with the Media Application Framewoek (MAFW).

The Media Application Framework (MAFW) provides an open, flexible and extensible layer that eases the development of multimedia applications for the Maemo platform. MAFW API

You normally start with obtaining MafwRegistry object and loading plugin(s):

/* gcc mafw.c -o mafw -g --std=gnu99 -Wall $(pkg-config --libs --cflags mafw glib-2.0) */
 
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libmafw/mafw.h>
 
int main(int agrc, char** argv)
{
g_type_init();
 
MafwRegistry *registry = mafw_registry_get_instance();
 
GError *error = NULL;
if(!mafw_registry_load_plugin(registry, "mafw-gst-renderer", &error)) {
if(error) {
printf("%s\n", error->message);
g_error_free(error);
}
printf("Cannot load mafw_gst_renderer plugin\n");
exit(1);
}
 
GList *renderers = mafw_registry_get_renderers(registry);
print_extensions(renderers);
GList *sources = mafw_registry_get_sources(registry);
print_extensions(sources);
 
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
 
exit(EXIT_SUCCESS);
}

The next step is to browse properties provided by an extension and listening for "property-changed" signal (note that you can connect to "property-changed::volume" if you want to monitor only "volume" property):

static void print_extensions(GList *extensions)
{
for(GList *iter = extensions; iter; iter = iter->next) {
MafwExtension* extension = (MafwExtension*)iter->data;
g_signal_connect(extension, "property-changed",
G_CALLBACK(property_changed_cb), NULL);
const gchar *name = mafw_extension_get_name(extension);
const gchar *uuid = mafw_extension_get_uuid(extension);
const gchar *plugin = mafw_extension_get_plugin(extension);
printf("%s[%s]:%s\n", name, uuid, plugin);
const GPtrArray *properties = mafw_extension_list_properties(extension);
for(int i = 0; i < properties->len; i++) {
MafwExtensionProperty *property = properties->pdata[i];
mafw_extension_get_property(extension, property->name,
property_get_cb, NULL);
}
}
}

Callbacks are defined like this:

static void property_get_cb(MafwExtension *self, const gchar *name,
GValue *value, gpointer udata, const GError *error)
{
if(error) {
printf("%s\n", error->message);
} else {
print_property(name, value);
}
}
 
static void property_changed_cb(MafwExtension *self, const gchar *name,
GValue *value, gpointer udata)
{
print_property(name, value);
}

Printing a property value (dealing with GValue)

static void print_property(const gchar *name, GValue *value)
{
switch(G_VALUE_TYPE(value)) {
case G_TYPE_UINT:
printf("\t%s[%s] = %u\n", name, G_VALUE_TYPE_NAME(value),
g_value_get_uint(value));
break;
case G_TYPE_INT:
printf("\t%s[%s] = %i\n", name, G_VALUE_TYPE_NAME(value),
g_value_get_int(value));
break;
case G_TYPE_BOOLEAN:
printf("\t%s[%s] = %i\n", name, G_VALUE_TYPE_NAME(value),
g_value_get_boolean(value));
break;
case G_TYPE_STRING:
printf("\t%s[%s] = \"%s\"\n", name, G_VALUE_TYPE_NAME(value),
g_value_get_string(value));
break;
default:
printf("\t%s[%s]\n", name, G_VALUE_TYPE_NAME(value));
break;
}
}

The property of your interest is "volume".

This page was last modified on 20 April 2013, at 23:06.
27 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×