update
Набыдлокодил чуть-чуть :
Код: Выделить всё
/*
Compile: gcc main.c -o audioplayer -Wall `pkg-config --libs --cflags gtk+-3.0 gstreamer-1.0` -lgstplayer-1.0 -lgobject-2.0 -lglib-2.0
*/
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gst/player/player.h>
typedef struct _PData {
GstPlayer *aplayer;
gchar *uri;
GtkWidget *window;
GtkWidget *box;
GtkWidget *button;
GtkWidget *progress;
gboolean playing;
} PData;
static void window_close (GtkWidget *widget, PData *data) {
gst_object_unref (data->aplayer);
g_free (data);
gtk_main_quit ();
}
static void button_clicked (GtkWidget *widget, PData *data, GstPlayerState state) {
GtkWidget *play_icon;
gboolean playing = FALSE;
playing = data->playing;
if (playing) {
gst_player_pause (data->aplayer);
} else {
gst_player_play (data->aplayer);
}
play_icon = gtk_image_new_from_icon_name
( (!playing)
?"media-playback-pause-symbolic"
:"media-playback-start-symbolic",
GTK_ICON_SIZE_BUTTON );
gtk_button_set_image(GTK_BUTTON(data->button), play_icon);
data->playing = (!playing);
}
static void state_changed (PData *data, GstPlayerState state) {
g_print ("State: %s \n", gst_player_state_get_name (state));
}
int main (int argc, char *argv[]) {
PData *data = g_malloc(sizeof(*data));
gchar *filename;
if (argc != 2) {
g_print ("Usage: %s /path/to/audiofile\n", argv[0]);
return -1;
}
data->uri = g_file_get_uri(g_file_new_for_commandline_arg (argv[1]));
filename = g_path_get_basename (argv[1]);
gtk_init (&argc, &argv);
/***** GUI *****/
data->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW(data->window), "Simple Audio Player");
gtk_window_set_default_size (GTK_WINDOW(data->window), 400, 1);
gtk_window_set_resizable (GTK_WINDOW(data->window), FALSE);
data->box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
data->button = gtk_button_new_from_icon_name ("media-playback-start-symbolic",
GTK_ICON_SIZE_BUTTON);
data->progress = gtk_progress_bar_new ();
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data->progress), 1.0);
gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (data->progress), TRUE);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (data->progress), filename );
gtk_container_add
(GTK_CONTAINER(data->window), data->box);
gtk_box_pack_start
(GTK_BOX(data->box), data->button, FALSE, TRUE, 0);
gtk_box_pack_end
(GTK_BOX(data->box), data->progress, TRUE, TRUE, 0);
/***** GstPlayer *****/
data->playing = FALSE;
data->aplayer = gst_player_new (NULL,
gst_player_g_main_context_signal_dispatcher_new (NULL));
gst_player_set_uri (data->aplayer, data->uri);
gst_player_set_video_track_enabled (data->aplayer, FALSE);
/***** Signals *****/
g_signal_connect (GTK_WINDOW(data->window),
"destroy",
G_CALLBACK(window_close),
data );
g_signal_connect(GTK_BUTTON(data->button),
"clicked",
G_CALLBACK(button_clicked),
data );
g_signal_connect (GST_PLAYER(data->aplayer),
"state-changed",
G_CALLBACK (state_changed),
data );
g_signal_connect (GST_PLAYER(data->aplayer),
"end-of-stream",
G_CALLBACK (window_close),
data );
gtk_widget_show_all (data->window);
gtk_main ();
return 0;
}