- 论坛徽章:
- 0
|
源码如下:
#include
#include
//#include
static gboolean
bus_callback(GstBus *bus,
GstMessage *msg,
gpointer data)
{
GMainLoop *loop = data;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
g_print("End-of-stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR:
{
gchar *debug;
GError *err;
gst_message_parse_error(msg, &err, &debug);
g_free(debug);
g_print("Error: %s\n", err->message);
g_error_free(err);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
int func_loop(void *data)
{
GMainLoop *loop = data;
g_main_loop_run(loop);
return 0;
}
gint
main(gint argc,
gchar *argv[])
{
GMainLoop *loop;
GstElement *play;
int quit = 0;
SDL_Event event;
int paused = 0;
GstElement *volume;
double volumeValue;
/* init GStreamer */
gst_init(&argc, &argv);
if (SDL_Init(SDL_INIT_EVERYTHING) \n", argv[0]);
return -1;
}
/* set up */
play = gst_element_factory_make("playbin", "play");
g_object_set(G_OBJECT(play), "uri", argv[1], NULL);
gst_bus_add_watch(gst_pipeline_get_bus(GST_PIPELINE(play)), bus_callback, loop);
gst_element_set_state(play, GST_STATE_PLAYING);
volume = gst_bin_get_by_name(GST_BIN(play), "volume");
if (NULL == volume) {
fprintf(stderr, "No volume\n");
}
//g_object_set(volume, "volume", 5, NULL);
g_object_get(volume, "volume", &volumeValue, NULL);
fprintf(stderr, "%f\n", volumeValue);
/* g_object_set(volume, "volume", 2.0, NULL); */
/* g_object_get(volume, "volume", &volumeValue, NULL); */
/* fprintf(stderr, "%f\n", volumeValue); */
/* now run */
//g_main_loop_run(loop);
//SDL_CreateThread(func_loop, loop);
while (0 == quit) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
quit = 1;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_p:
if (1 == paused) {
gst_element_set_state(play, GST_STATE_PLAYING);
} else {
gst_element_set_state(play, GST_STATE_PAUSED);
}
paused ^= 1;
break;
case SDLK_LEFT:
g_object_get(volume, "volume", &volumeValue, NULL);
g_object_set(volume, "volume", (volumeValue - 1 > 0) ? volumeValue - 1 : 0, NULL);
break;
case SDLK_RIGHT:
g_object_get(volume, "volume", &volumeValue, NULL);
g_object_set(volume, "volume", (volumeValue + 1
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/6646/showart_160967.html |
|