Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: mp3player.c
- * Author: Alvin Delagon
- * Summary: A command-line mp3 player using gstreamer
- */
- #include <gst/gst.h>
- int main (int argc, char *argv[])
- {
- GstElement *pipeline;
- GstElement *filesrc, *mad, *audioconvert, *alsasink;
- /* initialize gst */
- const gchar *nano_str;
- guint major, minor, micro, nano;
- gst_version (&major, &minor, µ, &nano);
- if (nano == 1)
- nano_str = "(CVS)";
- else if (nano == 2)
- nano_str = "(Prerelease)";
- else
- nano_str = "";
- g_print ("Using gstreamer version: %d.%d.%d %s\n", major, minor, micro, nano_str);
- gst_init (&argc, &argv);
- g_print ("Creating elements...\n");
- /* Create Elements */
- filesrc = gst_element_factory_make ("filesrc", "source");
- if (filesrc == NULL)
- {
- g_print ("Failed to create filesrc element");
- return -1;
- }
- mad = gst_element_factory_make ("mad", "decoder");
- if (mad == NULL)
- {
- g_print ("Failed to create mad element");
- return -1;
- }
- audioconvert = gst_element_factory_make ("audioconvert", "converter");
- if (audioconvert == NULL)
- {
- g_print ("Failed to create audioconvert element");
- return -1;
- }
- alsasink = gst_element_factory_make ("alsasink", "sink");
- if (alsasink == NULL)
- {
- g_print ("Failed to create alsasink element");
- return -1;
- }
- g_print ("Building pipeline...\n");
- /* Add Elements to pipeline*/
- pipeline = gst_pipeline_new ("mp3-pipeline");
- gst_bin_add_many (GST_BIN (pipeline), filesrc, mad, audioconvert, alsasink, NULL);
- g_print ("Linking elements...\n");
- /* Link Elements */
- if (!gst_element_link_many (filesrc, mad, audioconvert, alsasink, NULL))
- g_warning ("Failed to link elements!\n");
- /* Set filesrc location property */
- if (argv[1] == NULL)
- {
- g_print ("mp3 file is not provided. usage: mp3player [file]\n");
- return -1;
- }
- g_print ("Playing file: %s\n", argv[1]);
- g_object_set (filesrc, "location", argv[1], NULL);
- /* Set pipeline state to PLAYING */
- gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
- /* Application loop (We'll use gtk_main() here soon) */
- while (1)
- {
- g_usleep(G_USEC_PER_SEC);
- g_print (".");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement