44 #include <glib/gi18n.h>
51 #include "gstreamer_control.h"
56 #include "utilities.h"
57 #include "player_tab.h"
58 #include "mp3splt-gtk.h"
60 extern int selected_player;
64 const gchar *song_artist = NULL;
65 const gchar *song_title = NULL;
68 GstElement *play = NULL;
70 gint _gstreamer_is_running = FALSE;
71 extern GtkWidget *playlist_box;
72 extern GtkWidget *player_vbox;
77 static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
79 switch (GST_MESSAGE_TYPE(msg))
81 case GST_MESSAGE_ERROR:
86 gst_message_parse_error (msg, &error, &debug);
89 gchar *message = NULL;
90 if (error->message != NULL)
92 gint malloc_size = strlen(error->message) + 20;
93 message = malloc(
sizeof(
char) * malloc_size);
96 memset(message,
'\0',malloc_size);
97 g_snprintf(message, malloc_size,_(
"gstreamer error: %s"),error->message);
109 case GST_MESSAGE_WARNING:
114 gst_message_parse_warning(msg, &error, &debug);
117 gchar *message = NULL;
118 if (error->message != NULL)
120 gint malloc_size = strlen(error->message) + 20;
121 message = malloc(
sizeof(
char) * malloc_size);
124 memset(message,
'\0',malloc_size);
125 g_snprintf(message, malloc_size,_(
"Warning: %s"),error->message);
134 g_error_free (error);
137 case GST_MESSAGE_INFO:
142 gst_message_parse_info(msg, &error, &debug);
145 gchar *message = NULL;
146 if (error->message != NULL)
148 gint malloc_size = strlen(error->message) + 20;
149 message = malloc(
sizeof(
char) * malloc_size);
152 memset(message,
'\0',malloc_size);
153 g_snprintf(message, malloc_size,_(
"Info: %s"),error->message);
162 g_error_free (error);
165 case GST_MESSAGE_TAG:
167 GstTagList *tag_list = NULL;
168 gst_message_parse_tag(msg, &tag_list);
170 gint number_of_stream = 0;
171 g_object_get(play,
"current-audio", &number_of_stream, NULL);
174 const GValue *val = gst_tag_list_get_value_index(tag_list, GST_TAG_ARTIST,
178 song_artist = g_value_get_string(val);
182 val = gst_tag_list_get_value_index(tag_list, GST_TAG_TITLE, number_of_stream);
185 song_title = g_value_get_string(val);
189 val = gst_tag_list_get_value_index(tag_list, GST_TAG_BITRATE, number_of_stream);
192 rate = g_value_get_uint(val);
212 gint number_of_stream = 0;
213 g_object_get(play,
"current-audio", &number_of_stream, NULL);
216 GList *streaminfo = NULL;
217 g_object_get(play,
"stream-info", &streaminfo, NULL);
219 gchar rate_str[32] = {
'\0' };
220 gchar freq_str[32] = {
'\0' };
221 gchar nch_str[32] = {
'\0' };
223 gchar *_Kbps = _(
"Kbps");
224 gchar *_Khz = _(
"Khz");
227 GObject *
object = g_list_nth_data(streaminfo, number_of_stream);
230 GstObject *obj = NULL;
231 g_object_get(G_OBJECT(
object),
"object", &obj, NULL);
234 GstCaps *caps = NULL;
235 g_object_get(obj,
"caps", &caps, NULL);
239 GstStructure *structure = NULL;
240 structure = gst_caps_get_structure(caps, number_of_stream);
243 gst_structure_get_int(structure,
"rate", &freq);
244 gst_structure_get_int(structure,
"channels", &nch);
246 gst_caps_unref(caps);
249 g_snprintf(rate_str,32,
"%d", rate/1000);
250 g_snprintf(freq_str,32,
"%d", freq/1000);
254 snprintf(nch_str, 32,
"%s", _(
"stereo"));
258 snprintf(nch_str, 32,
"%s", _(
"mono"));
264 g_snprintf(total_infos,512,
266 rate_str,_Kbps,freq_str, _Khz,nch_str);
270 total_infos[0] =
'\0';
296 if (song_artist || song_title)
298 gint title_size = 20;
302 title_size += strlen(song_artist);
307 title_size += strlen(song_title);
310 gchar *title = malloc(
sizeof(
char) * title_size);
311 memset(title, title_size,
'\0');
313 if (song_artist && song_title)
315 g_snprintf(title, title_size,
"%s - %s", song_artist, song_title);
317 else if (song_title && !song_artist)
319 g_snprintf(title, title_size,
"%s", song_title);
321 else if (song_artist && !song_title)
323 g_snprintf(title, title_size,
"%s", song_artist);
333 gchar *file = strrchr(fname, G_DIR_SEPARATOR);
336 gchar *alloced_file = strdup(file+1);
358 GstQuery *query = gst_query_new_position(GST_FORMAT_TIME);
361 if (gst_element_query(play, query))
363 gst_query_parse_position(query, NULL, &time);
366 gst_query_unref(query);
368 return (gint) (time / GST_MSECOND);
382 gst_object_unref(play);
385 gst_init(NULL, NULL);
388 gst_default_registry_add_path(
"./");
391 play = gst_element_factory_make(
"playbin",
"play");
395 gtk_widget_show_all(playlist_box);
397 _gstreamer_is_running = TRUE;
398 bus = gst_pipeline_get_bus (GST_PIPELINE (play));
399 gst_bus_add_watch(bus, bus_call, NULL);
400 gst_object_unref(bus);
404 GList *song_list = NULL;
405 song_list = g_list_append(song_list, strdup(fname));
448 while ((song = g_list_nth_data(list, i)) != NULL)
454 len_uri += strlen(song);
455 uri = malloc(
sizeof(
char) * len_uri);
456 g_snprintf(uri,len_uri,
"file://%s",song);
457 g_object_set(G_OBJECT(play),
"uri", uri, NULL);
476 g_object_set(G_OBJECT(play),
"volume", (
double) volume / 100.0 * 2, NULL);
488 g_object_get(G_OBJECT(play),
"volume", &volume, NULL);
490 return (gint) (volume / 2 * 100);
509 return _gstreamer_is_running;
518 gst_element_get_state(play, &state, NULL, GST_CLOCK_TIME_NONE);
520 if (state == GST_STATE_PAUSED)
541 gst_element_get_state(play, &state, NULL, GST_CLOCK_TIME_NONE);
543 if (state == GST_STATE_PLAYING)
549 gst_element_set_state(play, GST_STATE_PLAYING);
559 gst_element_set_state(play, GST_STATE_NULL);
569 gst_element_get_state(play, &state, NULL, GST_CLOCK_TIME_NONE);
571 if (state == GST_STATE_PLAYING)
573 gst_element_set_state(play, GST_STATE_PAUSED);
597 gst_element_seek(play,
598 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
599 GST_SEEK_TYPE_SET, position * GST_MSECOND, 0, 0);
608 GstQuery *query = gst_query_new_duration(GST_FORMAT_TIME);
611 if (gst_element_query(play,query))
614 gst_query_parse_duration (query, NULL, &total_time);
615 time = (gint) (total_time / GST_MSECOND);
618 gst_query_unref(query);
634 gst_element_get_state(play, &state, NULL, GST_CLOCK_TIME_NONE);
636 if ((state == GST_STATE_PLAYING) || (state == GST_STATE_PAUSED))
656 gst_element_set_state(play, GST_STATE_NULL);
658 _gstreamer_is_running = FALSE;