Play and pause buttons work

They play and pause music...
This commit is contained in:
Bryan Schumaker 2011-08-20 12:12:53 -04:00
parent 8c49544efd
commit ae5b3a358e
3 changed files with 30 additions and 4 deletions

View File

@ -1,5 +1,16 @@
#include <ocarina/button.h>
#include <libsaria/audio.h>
#include <libsaria/libsaria.h>
#define reg_on_click(func) \
static void on_click_##func(GtkWidget *button, GdkEvent *event, gpointer data)\
{ \
func(); \
}
#define on_click(func) \
on_click_##func
GtkWidget *make_button(const gchar *stockid, GtkIconSize size)
{
@ -12,12 +23,18 @@ GtkWidget *make_button(const gchar *stockid, GtkIconSize size)
return button;
}
reg_on_click(gst_play);
GtkWidget *make_play_button(GtkIconSize size)
{
return make_button(GTK_STOCK_MEDIA_PLAY, size);
GtkWidget *button = make_button(GTK_STOCK_MEDIA_PLAY, size);
GTK_CONNECT(button, "clicked", on_click(gst_play), NULL);
return button;
}
reg_on_click(gst_pause);
GtkWidget *make_pause_button(GtkIconSize size)
{
return make_button(GTK_STOCK_MEDIA_PAUSE, size);
GtkWidget *button = make_button(GTK_STOCK_MEDIA_PAUSE, size);
GTK_CONNECT(button, "clicked", on_click(gst_pause), NULL);
return button;
}

View File

@ -6,5 +6,7 @@ extern "C" {
}
void audio_init(int, char **);
void gst_play();
void gst_pause();
#endif /* LIBSARIA_AUDIO_H */

View File

@ -23,11 +23,18 @@ void load_file(string file)
g_object_set(G_OBJECT(player), "uri", uri.c_str(), NULL);
}
void play()
void gst_play()
{
print("Playing!");
change_state(GST_STATE_PLAYING);
}
void gst_pause()
{
print("Paused!");
change_state(GST_STATE_PAUSED);
}
void audio_init(int argc, char **argv)
{
print("Initializing audio...");
@ -36,5 +43,5 @@ void audio_init(int argc, char **argv)
player = gst_element_factory_make("playbin2", "player");
if (argc > 1)
load_file(argv[1]);
play();
gst_play();
}