From: phantomjinx <pha...@us...> - 2010-09-03 23:12:21
|
commit 752a777121c4b3a68b374aa3a166d7c389efe619 Author: phantomjinx <p.g...@ph...> Date: Sat Sep 4 00:11:04 2010 +0100 Fix media player volume control and have it change the audio volume * Set the volume according to a preference that is saved to preference file * Volume plumbed into the audio of the gstreamer playbin plugins/media_player/media_player.c | 37 ++++++++++++++++++++++++++----- plugins/media_player/media_player.glade | 8 ++++-- 2 files changed, 36 insertions(+), 9 deletions(-) --- diff --git a/plugins/media_player/media_player.c b/plugins/media_player/media_player.c index dfafbdf..9cf57cd 100644 --- a/plugins/media_player/media_player.c +++ b/plugins/media_player/media_player.c @@ -35,6 +35,7 @@ #include "libgtkpod/file.h" #include "libgtkpod/directories.h" #include "libgtkpod/misc.h" +#include "libgtkpod/prefs.h" #include "plugin.h" #include "media_player.h" @@ -42,6 +43,9 @@ #define M_LN10 (log(10.0)) #endif +#define MEDIA_PLAYER_VOLUME_KEY "media_player_volume_key" +#define MEDIA_PLAYER_VOLUME_MUTE "media_player_volume_mute" + static MediaPlayer *player; static int pipeline_bus_watch_cb(GstBus *bus, GstMessage *msg, gpointer data); @@ -102,12 +106,15 @@ static gboolean set_scale_position(GstElement *pipeline) { return FALSE; } -static void update_volume(gboolean value) { +static void update_volume(gdouble value) { if (!player) return; - player->volume_level = exp(value / 20.0 * M_LN10); - // g_object_set(player->volume_element, "volume", player->volume_level, NULL); + player->volume_level = value / 10; + prefs_set_double(MEDIA_PLAYER_VOLUME_KEY, player->volume_level); + prefs_set_double(MEDIA_PLAYER_VOLUME_MUTE, player->volume_level == 0 ? 1 : 0); + + g_object_set(player->play_element, "volume", player->volume_level, NULL); } static gboolean volume_changed_cb(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data) { @@ -213,6 +220,7 @@ static void thread_play_song() { uri = g_strconcat("file://", track_name, NULL); player->play_element = gst_element_factory_make("playbin2", "play"); g_object_set(G_OBJECT (player->play_element), "uri", uri, NULL); + g_object_set(player->play_element, "volume", player->volume_level, NULL); bus = gst_pipeline_get_bus(GST_PIPELINE (player->play_element)); gst_bus_add_watch(bus, pipeline_bus_watch_cb, player->loop); //Add a watch to the bus @@ -468,9 +476,26 @@ void init_media_player(GtkWidget *parent) { player->shuffle = FALSE; player->play_element = NULL; - // gtk_widget_show(player->song_label); + /* Set the volume based on preference */ + gint volume_mute = prefs_get_int(MEDIA_PLAYER_VOLUME_MUTE); + if (volume_mute == 1) { + player->volume_level = 0; + } + else { + gdouble volume = prefs_get_double(MEDIA_PLAYER_VOLUME_KEY); + if (volume == 0) { + /* + * The preference is at its default value so set it to + * the default of level 0.5 + */ + player->volume_level = 0.5; + } + else { + player->volume_level = volume; + } + } + gtk_widget_show_all(player->media_panel); -// gtk_widget_realize(player->video_widget); g_object_unref(xml); } @@ -500,7 +525,7 @@ G_MODULE_EXPORT void on_volume_button_clicked_cb(GtkToolButton *toolbutton, gpoi g_message("Volume level: %f", player->volume_level); - gtk_range_set_value(GTK_RANGE(vol_scale), player->volume_level); + gtk_range_set_value(GTK_RANGE(vol_scale), (player->volume_level * 10)); g_signal_connect(G_OBJECT (vol_scale), "change-value", G_CALLBACK(volume_changed_cb), diff --git a/plugins/media_player/media_player.glade b/plugins/media_player/media_player.glade index 0d6eef3..a7edece 100644 --- a/plugins/media_player/media_player.glade +++ b/plugins/media_player/media_player.glade @@ -17,7 +17,6 @@ <property name="visible">True</property> <property name="xalign">0</property> <property name="xpad">6</property> - <property name="label" translatable="yes"></property> </widget> <packing> <property name="position">0</property> @@ -175,9 +174,12 @@ <property name="is_focus">True</property> <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK</property> <property name="orientation">vertical</property> - <property name="adjustment">0 -90 10 0.20000000000000001 2 2</property> + <property name="adjustment">5 0 10 1 1 0</property> <property name="inverted">True</property> - <property name="fill_level">10</property> + <property name="lower_stepper_sensitivity">off</property> + <property name="upper_stepper_sensitivity">off</property> + <property name="restrict_to_fill_level">False</property> + <property name="fill_level">100</property> <property name="digits">0</property> </widget> </child> |