2 * This file is a part of libhildon
4 * Copyright (C) 2005-2008 Nokia Corporation. All rights reserved.
6 * Contact: Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-sound
27 * @short_description: libcanberra-based utility function for playing a sound.
32 #include <gconf/gconf-client.h>
35 #include "hildon-sound.h"
37 #define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
40 * hildon_play_system_sound:
41 * @sample: sound file to play
43 * Plays the given sample using libcanberra.
44 * Volume level is received from gconf.
47 hildon_play_system_sound(const gchar *sample)
51 ca_context *ca_con = NULL;
52 ca_proplist *pl = NULL;
54 #if 0 /* FIXME: Check volume handling. Would be great not to use Gconf... */
60 * The volume is from -0dB to -6dB,
61 The full volume is marked as 2 in gconf */
62 client = gconf_client_get_default ();
63 value = gconf_client_get (client, ALARM_GCONF_PATH, NULL);
65 /* We want error cases to match full volume, not silence, so
66 we do not want to use gconf_client_get_int */
67 if (!value || value->type != GCONF_VALUE_INT)
70 gconf_vol = gconf_value_get_int(value);
73 gconf_value_free(value);
74 g_object_unref (client);
76 volume = ((1.0 - (float)gconf_vol / 2.0)) * (-6.0);
79 if ((ret = ca_context_create(&ca_con)) != CA_SUCCESS) {
80 g_warning("ca_context_create: %s\n", ca_strerror(ret));
83 if ((ret = ca_context_open(ca_con)) != CA_SUCCESS) {
84 g_warning("ca_context_open: %s\n", ca_strerror(ret));
85 ca_context_destroy(ca_con);
88 ca_proplist_create(&pl);
89 ca_proplist_sets(pl, CA_PROP_MEDIA_FILENAME, sample);
90 ca_proplist_setf(pl, CA_PROP_CANBERRA_VOLUME, "%f", volume);
92 ret = ca_context_play_full(ca_con, 0, pl, NULL, NULL);
93 g_debug("ca_context_play_full (vol %f): %s\n", volume, ca_strerror(ret));
95 ca_proplist_destroy(pl);
96 ca_context_destroy(ca_con);