commit 31f2666d9baf05576c486e11b967d4ff56f49bd7
Author: phantomjinx <[email protected]>
Date: Wed Jul 28 22:26:42 2010 +0100
Refactorings of media player
* Prototype up and running and produces sound.
plugins/media_player/media_player.c | 392 ++++++++++++++++++-------------
plugins/media_player/media_player.glade | 6 +-
plugins/media_player/media_player.h | 23 ++-
3 files changed, 248 insertions(+), 173 deletions(-)
---
diff --git a/plugins/media_player/media_player.c
b/plugins/media_player/media_player.c
index 02933e4..74c0f03 100644
--- a/plugins/media_player/media_player.c
+++ b/plugins/media_player/media_player.c
@@ -30,11 +30,8 @@
#endif
#include <math.h>
-#include <gst/gst.h>
#include <gst/interfaces/xoverlay.h>
-#include <gdk/gdkx.h>
-#include <gtk/gtk.h>
-#include <gdk/gdk.h>
+//#include <gdk/gdkx.h>
#include "libgtkpod/itdb.h"
#include "libgtkpod/file.h"
#include "libgtkpod/directories.h"
@@ -44,27 +41,16 @@
static MediaPlayer *player;
-GMainLoop *loop;
-GstElement *pipeline, *audio, *audiomixer, *volume;
-GstElement *src, *dec, *conv, *sink;
-GstPad *audiopad;
-
-GstElement *video, *videosink, *videoconv;
-GstPad *videopad;
+//GstElement *video, *videosink, *videoconv;
+//GstPad *videopad;
GstBus *bus;
-static gboolean prevbut = FALSE;
-static gboolean stopall = FALSE;
-static gboolean shuffle = TRUE;
-static GThread *thread = NULL;
-gboolean hasvideo = FALSE;
static int my_bus_callback(GstBus *bus, GstMessage *msg, gpointer data) {
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
gtk_range_set_range(GTK_RANGE(player->song_scale), 0, 1);
gtk_range_set_value(GTK_RANGE(player->song_scale), 0);
- gtk_label_set_text(GTK_LABEL(player->song_label), "");
g_main_loop_quit(data);
break;
case GST_MESSAGE_ERROR: {
@@ -91,10 +77,13 @@ static gboolean set_scale_range(GstElement *pipeline) {
GstFormat fmt = GST_FORMAT_TIME;
gint64 len;
- if (loop == NULL || GST_OBJECT_IS_DISPOSING(pipeline))
+ if (!player)
+ return FALSE;
+
+ if (!player->loop || GST_OBJECT_IS_DISPOSING(pipeline))
return FALSE;
- if (loop != NULL || g_main_loop_is_running(loop)) {
+ if (g_main_loop_is_running(player->loop)) {
if (gst_element_query_duration(pipeline, &fmt, &len)) {
gtk_range_set_range(GTK_RANGE(player->song_scale), 0,
(((GstClockTime) (len)) / GST_SECOND));
// if (icon)
@@ -112,26 +101,28 @@ static gboolean set_scale_position(GstElement *pipeline) {
gint64 pos;
gint64 len;
- if (loop == NULL || thread == NULL || !g_main_loop_is_running(loop))
+ if (player == NULL)
return FALSE;
- if (loop != NULL || g_main_loop_is_running(loop)) {
- if (gst_element_query_position(pipeline, &fmt, &pos)) {
- gint seconds = ((GstClockTime) pos) / GST_SECOND;
- gint length;
- gchar *label;
-
- gst_element_query_duration(pipeline, &fmt, &len);
- length = ((GstClockTime) len) / GST_SECOND;
-
- label
- = g_strdup_printf(_("%s (%d:%02d of %d:%02d)"), (gchar *)
g_object_get_data(G_OBJECT (player->song_label), "tr_title"), seconds
- / 60, seconds % 60, length / 60, length % 60);
- gtk_range_set_value(GTK_RANGE(player->song_scale), seconds);
- gtk_label_set_text(GTK_LABEL(player->song_label), label);
- g_free(label);
- return TRUE;
- }
+ if (!player->loop || !player->thread)
+ return FALSE;
+
+ if (!g_main_loop_is_running(player->loop))
+ return FALSE;
+
+ if (gst_element_query_position(pipeline, &fmt, &pos)) {
+ gint seconds = ((GstClockTime) pos) / GST_SECOND;
+ gint length;
+ gchar *label;
+
+ gst_element_query_duration(pipeline, &fmt, &len);
+ length = ((GstClockTime) len) / GST_SECOND;
+
+ label = g_strdup_printf(_("%d:%02d of %d:%02d"), seconds / 60, seconds
% 60, length / 60, length % 60);
+ gtk_range_set_value(GTK_RANGE(player->song_scale), seconds);
+ gtk_label_set_text(GTK_LABEL(player->song_time_label), label);
+ g_free(label);
+ return TRUE;
}
return FALSE;
@@ -140,29 +131,36 @@ static gboolean set_scale_position(GstElement *pipeline) {
#define M_LN10 (log(10.0))
#endif
-static void volume_changed_callback(GtkWidget *widget, GstElement* volume) {
- gdouble value;
- gdouble level;
+static void update_volume(gboolean value) {
+ if (!player)
+ return;
- value = gtk_range_get_value(GTK_RANGE(widget));
- level = exp(value / 20.0 * M_LN10);
- g_object_set(volume, "volume", level, NULL);
+ player->volume_level = exp(value / 20.0 * M_LN10);
+ g_object_set(player->volume_element, "volume", player->volume_level, NULL);
}
-static void cb_newpad(GstElement *decodebin, GstPad *pad, gboolean last,
gpointer data) {
+
+static gboolean volume_changed_cb(GtkRange *range, GtkScrollType scroll,
gdouble value, gpointer user_data) {
+ update_volume(value);
+ return FALSE;
+}
+
+static void new_decoded_pad_cb(GstElement *decodebin, GstPad *pad, gboolean
last, gpointer data) {
GstCaps *caps;
GstStructure *str;
- GstPad *audiopad2, *videopad2;
+ GstPad *audiopad2;
+ // , *videopad2;
+
+ if (!player)
+ return;
/* check media type */
caps = gst_pad_get_caps(pad);
str = gst_caps_get_structure(caps, 0);
- printf("string = %s\n", gst_structure_get_name(str));
const gchar *name = gst_structure_get_name(str);
if (g_strrstr(name, "audio")) {
/* only link once */
- audiopad2 = gst_element_get_pad(audio, "sink");
+ audiopad2 = gst_element_get_pad(player->audio, "sink");
if (GST_PAD_IS_LINKED (audiopad2)) {
- printf("audio pad is linked!unreffing\n");
g_object_unref(audiopad2);
return;
}
@@ -176,14 +174,14 @@ static void cb_newpad(GstElement *decodebin, GstPad *pad,
gboolean last, gpointe
if (g_strrstr(name, "video")) {
// only link once
- videopad2 = gst_element_get_pad(videoconv, "sink");
- if (GST_PAD_IS_LINKED (videopad2)) {
- printf("video pad is linked!unreffing\n");
- g_object_unref(videopad2);
- return;
- }
+ // videopad2 = gst_element_get_pad(videoconv, "sink");
+ // if (GST_PAD_IS_LINKED (videopad2)) {
+ // printf("video pad is linked!unreffing\n");
+ // g_object_unref(videopad2);
+ // return;
+ // }
// link'n'play
- gst_pad_link(pad, videopad2);
+ // gst_pad_link(pad, videopad2);
//set_video_mode (TRUE);//Not needed since We can't actually SEE the
video
}
@@ -191,62 +189,82 @@ static void cb_newpad(GstElement *decodebin, GstPad *pad,
gboolean last, gpointe
}
-static void playsong_real() {
+static void set_song_label(Track *track) {
+ if (!track)
+ return;
+
+ gchar *label;
+
+ // title by artist from album
+ if (!track->title)
+ label = _("No Track Title");
+ else {
+ label = g_strdup_printf("%s by %s from %s", track->title,
track->artist, track->album);
+ }
+ gtk_label_set_text(GTK_LABEL(player->song_label), label);
+ g_object_set_data(G_OBJECT (player->song_label), "tr_title", track->title);
+ g_object_set_data(G_OBJECT (player->song_label), "tr_artist",
track->artist);
+ g_free(label);
+}
+
+static void thread_play_song() {
GstStateChangeReturn sret;
GstState state;
gchar *str;
+ if (!player || !player->tracks)
+ return;
+
while (player->tracks) {
Track *tr = player->tracks->data;
g_return_if_fail(tr);
str = get_file_name_from_source(tr, SOURCE_PREFER_LOCAL);
if (str) {
-
- gtk_label_set_text(GTK_LABEL(player->song_label), tr->title); //
set label to title
- g_object_set_data(G_OBJECT (player->song_label), "tr_title",
tr->title);
- g_object_set_data(G_OBJECT (player->song_label), "tr_artist",
tr->artist);
+ set_song_label(tr);
/* init GStreamer */
- loop = g_main_loop_new(NULL, FALSE); // make new loop
+ player->loop = g_main_loop_new(NULL, FALSE); // make new loop
/* setup */
- pipeline = gst_pipeline_new("pipeline"); //Create our pipeline
- volume = gst_element_factory_make("volume", "volume"); // Create
volume element
- bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline)); // get
pipeline's bus
- gst_bus_add_watch(bus, my_bus_callback, loop); //Add a watch to
the bus
+ player->pipeline = gst_pipeline_new("pipeline"); //Create our
pipeline
+
+ bus = gst_pipeline_get_bus(GST_PIPELINE (player->pipeline)); //
get pipeline's bus
+ gst_bus_add_watch(bus, my_bus_callback, player->loop); //Add a
watch to the bus
gst_object_unref(bus); //unref the bus
- src = gst_element_factory_make("filesrc", "source"); //create the
file source
- g_object_set(G_OBJECT (src), "location", str, NULL); //set
location to the file location
- dec = gst_element_factory_make("decodebin", "decoder"); //create
our decodebing
- g_signal_connect (dec, "new-decoded-pad", G_CALLBACK (cb_newpad),
NULL); //signal to the new-decoded-pad(same as new-pad)
- gst_bin_add_many(GST_BIN (pipeline), src, dec, NULL); //add src
and dec to pipeline
- gst_element_link(src, dec); //link src and dec together
+ player->src = gst_element_factory_make("filesrc", "source");
//create the file source
+ g_object_set(G_OBJECT (player->src), "location", str, NULL); //set
location to the file location
+
+ player->dec = gst_element_factory_make("decodebin", "decoder");
//create our decodebin
+ g_signal_connect (player->dec, "new-decoded-pad", G_CALLBACK
(new_decoded_pad_cb), NULL); //signal to the new-decoded-pad(same as new-pad)
+
+ gst_bin_add_many(GST_BIN (player->pipeline), player->src,
player->dec, NULL); //add src and dec to pipeline
+ gst_element_link(player->src, player->dec); //link src and dec
together
/* create audio output */
- audio = gst_bin_new("audiobin"); //create our audio bin
- conv = gst_element_factory_make("audioconvert", "aconv"); //Create
audioconvert element
- audiopad = gst_element_get_pad(conv, "sink"); //get the
audioconvert pad
- sink = gst_element_factory_make("alsasink", "sink"); //create our
alsasink
+ player->audio = gst_bin_new("audiobin"); //create our audio bin
+ player->conv = gst_element_factory_make("audioconvert", "aconv");
//Create audioconvert element
+ player->audiopad = gst_element_get_pad(player->conv, "sink");
//get the audioconvert pad
+ player->sink = gst_element_factory_make("alsasink", "sink");
//create our alsasink
- gst_bin_add_many(GST_BIN (audio), conv, sink, volume, NULL); //add
volume, conv, and sink to audio
- gst_element_link(conv, sink); // link sink and conv
- gst_element_add_pad(audio, gst_ghost_pad_new("sink", audiopad));
// add pad to audio...?
- gst_object_unref(audiopad); //unref audiopad
- gst_bin_add(GST_BIN (pipeline), audio); //add audio to pipeline
+ gst_bin_add_many(GST_BIN (player->audio), player->conv,
player->sink, player->volume, NULL); //add volume, conv, and sink to audio
+ gst_element_link(player->conv, player->sink); // link sink and conv
+ gst_element_add_pad(player->audio, gst_ghost_pad_new("sink",
player->audiopad)); // add pad to audio...?
+ gst_object_unref(player->audiopad); //unref audiopad
+ gst_bin_add(GST_BIN (player->pipeline), player->audio); //add
audio to pipeline
/*create video output*/
- video = gst_bin_new("videobin"); //create videobin
- videoconv = gst_element_factory_make("ffmpegcolorspace", "vconv");
//make ffmpegcolorspace
+ // video = gst_bin_new("videobin"); //create videobin
+ // videoconv =
gst_element_factory_make("ffmpegcolorspace", "vconv"); //make ffmpegcolorspace
//videopad = gst_element_get_pad (videoconv, "sink"); //get
videoconv pad, why the hell am I getting
//videosink = gst_element_factory_make ("ximagesink", "sink");
//create video sink
//g_object_set (G_OBJECT (videosink), "force-aspect-ratio", TRUE,
NULL); //force aspect ratio
// gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink),
gdk_x11_drawable_get_xid (drawing_area->window)); //set the overlay to our
drawing area
//gst_element_link (videoconv, videosink); //link videoconv and
videosink
//gst_bin_add_many (GST_BIN (video),videoconv, videosink, NULL);
//add videoconv and videosink to video
- gst_bin_add(GST_BIN (video), videoconv);
+ // gst_bin_add(GST_BIN (video), videoconv);
//gst_object_unref (videopad); //unref videopad
- gst_bin_add(GST_BIN (pipeline), video);
+ // gst_bin_add(GST_BIN (pipeline), video);
//[NOTE] If file doesn't contain video, it crashes the program, so
commented out
/* Volume Control */
@@ -255,61 +273,57 @@ static void playsong_real() {
//g_signal_connect (vol_scale, "value-changed", G_CALLBACK
(volume_changed_callback), volume); //connect volume-changed signal
/* run */
- gst_element_set_state(pipeline, GST_STATE_PLAYING);// set state
- g_timeout_add(250, (GSourceFunc) set_scale_range, GST_PIPELINE
(pipeline));
- g_timeout_add(1000, (GSourceFunc) set_scale_position, GST_PIPELINE
(pipeline));
+ gst_element_set_state(player->pipeline, GST_STATE_PLAYING);// set
state
+ g_timeout_add(250, (GSourceFunc) set_scale_range, GST_PIPELINE
(player->pipeline));
+ g_timeout_add(1000, (GSourceFunc) set_scale_position, GST_PIPELINE
(player->pipeline));
//g_timeout_add (500, (GSourceFunc) checkinfo,
gst_pipeline_get_bus (GST_PIPELINE (pipeline)));
- g_main_loop_run(loop);
+ g_main_loop_run(player->loop);
/* cleanup */
- sret = gst_element_set_state(pipeline, GST_STATE_NULL);
+ sret = gst_element_set_state(player->pipeline, GST_STATE_NULL);
#ifndef NEW_PIPE_PER_FILE
- printf("New_pipe_per_file is NOT defined\n");
if (GST_STATE_CHANGE_ASYNC == sret) {
- if (gst_element_get_state(GST_ELEMENT (pipeline), &state,
NULL, GST_CLOCK_TIME_NONE)
+ if (gst_element_get_state(GST_ELEMENT (player->pipeline),
&state, NULL, GST_CLOCK_TIME_NONE)
== GST_STATE_CHANGE_FAILURE) {
- g_print("State change failed. Aborting");
break;
}
}
#endif
- gst_element_set_state(pipeline, GST_STATE_NULL);
+ gst_element_set_state(player->pipeline, GST_STATE_NULL);
g_free(str);//Free it since it is no longer needed.
}
- if (stopall)
+
+ if (player->stopButtonPressed)
break;
- if (!prevbut)
+
+ if (!player->previousButtonPressed)
player->tracks = g_list_next(player->tracks);
else
- prevbut = FALSE;
+ player->previousButtonPressed = FALSE;
}
- thread = NULL;
- stopall = FALSE;
+
+ player->thread = NULL;
+ player->stopButtonPressed = FALSE;
g_thread_exit(0);
}
-void seek_to_time(gint64 time_seconds) {
- if (loop == NULL || pipeline == NULL || thread == NULL ||
!g_main_loop_is_running(loop))
+static void waitforpipeline(int state) {
+ if (!player)
return;
- if (!gst_element_seek(pipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, time_seconds
- * 1000000000, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
- g_print("Seek failed!\n");
-}
-static void waitforpipeline(int state) {
- if (pipeline == NULL || thread == NULL)
+ if (!player->loop || !player->thread)
return;
GstState istate, ipending;
- gst_element_get_state(pipeline, &istate, &ipending, GST_CLOCK_TIME_NONE);
+ gst_element_get_state(player->pipeline, &istate, &ipending,
GST_CLOCK_TIME_NONE);
if (istate == GST_STATE_VOID_PENDING) {
return;
}
- gst_element_set_state(pipeline, state);
+ gst_element_set_state(player->pipeline, state);
do {
- gst_element_get_state(pipeline, &istate, &ipending,
GST_CLOCK_TIME_NONE);
+ gst_element_get_state(player->pipeline, &istate, &ipending,
GST_CLOCK_TIME_NONE);
if (istate == GST_STATE_VOID_PENDING) {
return;
@@ -320,81 +334,103 @@ static void waitforpipeline(int state) {
return;
}
-static void stop_song() {
- stopall = FALSE;
- if (loop != NULL && g_main_loop_is_running(loop))
- g_main_loop_quit(loop);
- waitforpipeline(1);
- gtk_range_set_range(GTK_RANGE(player->song_scale), 0, 1);
- gtk_range_set_value(GTK_RANGE(player->song_scale), 0);
- gtk_label_set_text(GTK_LABEL(player->song_label), "");
-}
+static void stop_song(gboolean stopButtonPressed) {
+ if (!player)
+ return;
-void stop_all_songs() {
- stopall = TRUE;
- if (loop != NULL && g_main_loop_is_running(loop)) {
- g_main_loop_quit(loop);
+ player->stopButtonPressed = stopButtonPressed;
+ if (player->loop && g_main_loop_is_running(player->loop)) {
+ g_main_loop_quit(player->loop);
}
- else
- stopall = FALSE;
+
waitforpipeline(1);
gtk_range_set_range(GTK_RANGE(player->song_scale), 0, 1);
gtk_range_set_value(GTK_RANGE(player->song_scale), 0);
- gtk_label_set_text(GTK_LABEL(player->song_label), "");
+ gtk_label_set_text(GTK_LABEL(player->song_time_label), "");
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(player->play_button),
GTK_STOCK_MEDIA_PLAY);
- gtk_widget_set_sensitive(player->song_scale, FALSE);
}
-void previous_song() {
- prevbut = TRUE;
+static void previous_song() {
+ if (!player)
+ return;
+
+ player->previousButtonPressed = TRUE;
player->tracks = g_list_previous (player->tracks);
- stop_song();
- //waitforpipeline (1);
+ stop_song(FALSE);
}
-void next_song() {
- stop_song();
- //waitforpipeline (1);
+static void next_song() {
+ stop_song(FALSE);
}
-int play_song() {
- stop_all_songs();
+static void play_song() {
GError *err1 = NULL;
+
+ if (!player)
+ return;
+
if (!g_thread_supported ()) {
g_thread_init(NULL);
gdk_threads_init();
}
- thread = g_thread_create ((GThreadFunc)playsong_real, NULL, TRUE, &err1);
- if (!thread) {
- printf("GStreamer thread creation failed: %s\n", err1->message);
+
+ stop_song(TRUE);
+
+ player->stopButtonPressed = FALSE;
+ gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(player->play_button),
GTK_STOCK_MEDIA_PLAY);
+
+ player->thread = g_thread_create ((GThreadFunc)thread_play_song, NULL,
TRUE, &err1);
+ if (!player->thread) {
+ gtkpod_statusbar_message("GStreamer thread creation failed: %s\n",
err1->message);
g_error_free(err1);
}
+
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(player->play_button),
GTK_STOCK_MEDIA_PAUSE);
- return 0;
}
-void pause_song() {
- if (loop == NULL || pipeline == NULL || thread == NULL ||
!g_main_loop_is_running(loop)) {
+static void pause_or_play_song() {
+ if (!player)
+ return;
+
+ if (!player->loop || !player->pipeline || !player->thread ||
!g_main_loop_is_running(player->loop)) {
play_song();
+ return;
}
GstState state, pending;
- gst_element_get_state(pipeline, &state, &pending, GST_CLOCK_TIME_NONE);
+ gst_element_get_state(player->pipeline, &state, &pending,
GST_CLOCK_TIME_NONE);
if (state == GST_STATE_PLAYING) {
- gst_element_set_state(pipeline, GST_STATE_PAUSED);
+ gst_element_set_state(player->pipeline, GST_STATE_PAUSED);
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(player->play_button),
GTK_STOCK_MEDIA_PLAY);
}
else if (state == GST_STATE_PAUSED) {
- gst_element_set_state(pipeline, GST_STATE_PLAYING);
+ gst_element_set_state(player->pipeline, GST_STATE_PLAYING);
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(player->play_button),
GTK_STOCK_MEDIA_PAUSE);
}
}
+void seek_to_time(gint64 time_seconds) {
+ if (!player)
+ return;
+
+ if (!player->loop || !player->pipeline || !player->thread)
+ return;
+
+ if (!g_main_loop_is_running(player->loop))
+ return;
+
+ if (!gst_element_seek(player->pipeline, 1.0, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, time_seconds
+ * 1000000000, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
+ g_print("Seek failed!\n");
+}
+
void set_selected_tracks(GList *tracks) {
if (!player)
return;
+ stop_song(TRUE);
+
if (player->tracks) {
g_list_free(player->tracks);
player->tracks = NULL;
@@ -402,7 +438,7 @@ void set_selected_tracks(GList *tracks) {
GList *l = g_list_copy(tracks);
//Does the same thing as generate_random_playlist()
- if (shuffle) {
+ if (player->shuffle) {
GRand *grand = g_rand_new();
while (l || (g_list_length(l) != 0)) {
/* get random number between 0 and g_list_length()-1 */
@@ -416,14 +452,8 @@ void set_selected_tracks(GList *tracks) {
else
player->tracks = l;
- Track *tr = player->tracks->data;
- gchar *str = get_file_name_from_source(tr, SOURCE_PREFER_LOCAL);
- if (str) {
- gtk_label_set_text(GTK_LABEL(player->song_label), tr->title); // set
label to title
- g_object_set_data(G_OBJECT (player->song_label), "tr_title",
tr->title);
- g_object_set_data(G_OBJECT (player->song_label), "tr_artist",
tr->artist);
- }
- g_free(str);
+ Track *track = player->tracks->data;
+ set_song_label(track);
}
void init_media_player(GtkWidget *parent) {
@@ -449,8 +479,6 @@ void init_media_player(GtkWidget *parent) {
player->next_button = gtkpod_xml_get_widget(xml, "next_button");
player->song_scale = gtkpod_xml_get_widget(xml, "song_scale");
- player->volume = 5;
-
glade_xml_signal_autoconnect(xml);
g_object_ref(player->media_panel);
@@ -462,6 +490,23 @@ void init_media_player(GtkWidget *parent) {
else
gtk_container_add(GTK_CONTAINER (parent), player->media_panel);
+ player->thread = NULL;
+ player->loop = NULL;
+ player->previousButtonPressed = FALSE;
+ player->stopButtonPressed = FALSE;
+ player->shuffle = FALSE;
+ player->volume_element = gst_element_factory_make("volume", "volume"); //
Create volume element
+ player->volume_level = 50;
+ player->pipeline = NULL;
+ player->audio = NULL;
+ player->audiomixer = NULL;
+ player->volume = NULL;
+ player->src = NULL;
+ player->dec = NULL;
+ player->conv = NULL;
+ player->sink = NULL;
+ player->audiopad = NULL;
+
gtk_widget_show(player->song_label);
gtk_widget_show_all(player->media_toolbar);
@@ -474,16 +519,6 @@ void destroy_media_player() {
player = NULL;
}
-static void update_volume(gint volume) {
- player->volume = volume;
-
-}
-
-static gboolean volume_changed_cb(GtkRange *range, GtkScrollType scroll,
gdouble value, gpointer user_data) {
- update_volume(value);
- return FALSE;
-}
-
G_MODULE_EXPORT gboolean on_volume_window_focus_out(GtkWidget *widget,
GdkEventFocus *event, gpointer data) {
GtkWidget *vol_scale = (GtkWidget *) g_object_get_data(G_OBJECT(widget),
"scale");
update_volume(gtk_range_get_value(GTK_RANGE(vol_scale)));
@@ -501,14 +536,14 @@ G_MODULE_EXPORT void
on_volume_button_clicked_cb(GtkToolButton *toolbutton, gpoi
vol_scale = gtkpod_xml_get_widget(xml, "volume_scale");
g_object_set_data(G_OBJECT(vol_window), "scale", vol_scale);
- gtk_range_set_value(GTK_RANGE(vol_scale), player->volume);
+ g_message("Volume level: %f", player->volume_level);
+
+ gtk_range_set_value(GTK_RANGE(vol_scale), player->volume_level);
g_signal_connect(G_OBJECT (vol_scale),
"change-value",
G_CALLBACK(volume_changed_cb),
NULL);
-
- // gtk_widget_set_events(vol_window, GDK_FOCUS_CHANGE_MASK);
g_signal_connect (G_OBJECT (vol_window),
"focus-out-event",
G_CALLBACK (on_volume_window_focus_out),
@@ -520,6 +555,27 @@ G_MODULE_EXPORT void
on_volume_button_clicked_cb(GtkToolButton *toolbutton, gpoi
g_object_unref(xml);
}
+G_MODULE_EXPORT void on_previous_button_clicked_cb(GtkToolButton *toolbutton,
gpointer *userdata) {
+ previous_song();
+}
+
+G_MODULE_EXPORT void on_play_button_clicked_cb(GtkToolButton *toolbutton,
gpointer *userdata) {
+ pause_or_play_song();
+}
+
+G_MODULE_EXPORT void on_stop_button_clicked_cb(GtkToolButton *toolbutton,
gpointer *userdata) {
+ stop_song(TRUE);
+}
+
+G_MODULE_EXPORT void on_next_button_clicked_cb(GtkToolButton *toolbutton,
gpointer *userdata) {
+ next_song();
+}
+
+G_MODULE_EXPORT gboolean on_song_scale_change_value_cb(GtkRange *range,
GtkScrollType scroll, gdouble value, gpointer user_data) {
+ seek_to_time(value);
+ return FALSE;
+}
+
void media_player_track_removed_cb(GtkPodApp *app, gpointer tk, gpointer data)
{
Track *old_track = tk;
if (!player)
diff --git a/plugins/media_player/media_player.glade
b/plugins/media_player/media_player.glade
index bd399c9..c19d065 100644
--- a/plugins/media_player/media_player.glade
+++ b/plugins/media_player/media_player.glade
@@ -58,6 +58,7 @@
<property name="homogeneous">True</property>
<child>
<widget class="GtkToolButton" id="previous_button">
+ <property name="width_request">35</property>
<property name="visible">True</property>
<property name="label"
translatable="yes">Previous</property>
<property name="use_underline">True</property>
@@ -70,6 +71,7 @@
</child>
<child>
<widget class="GtkToolButton" id="play_button">
+ <property name="width_request">35</property>
<property name="visible">True</property>
<property name="label" translatable="yes">Play</property>
<property name="use_underline">True</property>
@@ -120,7 +122,7 @@
<property name="digits">0</property>
<property name="draw_value">False</property>
<property name="value_pos">left</property>
- <signal name="change_value"
handler="on_song_scale_change_value"/>
+ <signal name="change_value"
handler="on_song_scale_change_value_cb"/>
</widget>
<packing>
<property name="position">1</property>
@@ -179,7 +181,7 @@
<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">9 0 11 1 1 0</property>
+ <property name="adjustment">0 -90 10 0.20000000000000001 2 2</property>
<property name="inverted">True</property>
<property name="fill_level">10</property>
<property name="digits">0</property>
diff --git a/plugins/media_player/media_player.h
b/plugins/media_player/media_player.h
index 9c04af7..b7d3e55 100644
--- a/plugins/media_player/media_player.h
+++ b/plugins/media_player/media_player.h
@@ -30,7 +30,8 @@
#ifndef __MEDIA_PLAYER_H__
#define __MEDIA_PLAYER_H__
-#include "glade/glade.h"
+#include <gtk/gtk.h>
+#include <gst/gst.h>
typedef struct {
GtkWidget *media_panel;
@@ -47,9 +48,25 @@ typedef struct {
gchar *glade_path;
- gint volume;
-
GList *tracks;
+ GThread *thread;
+ GMainLoop *loop;
+
+ gboolean previousButtonPressed;
+ gboolean stopButtonPressed;
+ gboolean shuffle;
+
+ gdouble volume_level;
+ GstElement *volume_element;
+ GstElement *pipeline;
+ GstElement *audio;
+ GstElement *audiomixer;
+ GstElement *volume;
+ GstElement *src;
+ GstElement *dec;
+ GstElement *conv;
+ GstElement *sink;
+ GstPad *audiopad;
} MediaPlayer;
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2