daily pastebin goal
22%
SHARE
TWEET

Alvin Delagon

a guest Apr 9th, 2009 184 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * File: mp3player.c
  3.  * Author: Alvin Delagon
  4.  * Summary: A command-line mp3 player using gstreamer
  5.  */
  6.  
  7. #include <gst/gst.h>
  8.  
  9. int main (int argc, char *argv[])
  10. {
  11.   GstElement *pipeline;
  12.   GstElement *filesrc, *mad, *audioconvert, *alsasink;
  13.  
  14.   /* initialize gst */
  15.   const gchar *nano_str;
  16.   guint major, minor, micro, nano;
  17.   gst_version (&major, &minor, &micro, &nano);
  18.   if (nano == 1)
  19.     nano_str = "(CVS)";
  20.   else if (nano == 2)
  21.     nano_str = "(Prerelease)";
  22.   else
  23.     nano_str = "";
  24.   g_print ("Using gstreamer version: %d.%d.%d %s\n", major, minor, micro, nano_str);
  25.   gst_init (&argc, &argv);
  26.  
  27.   g_print ("Creating elements...\n");
  28.   /* Create Elements */
  29.   filesrc = gst_element_factory_make ("filesrc", "source");
  30.   if (filesrc == NULL)
  31.     {
  32.       g_print ("Failed to create filesrc element");
  33.       return -1;
  34.     }
  35.   mad = gst_element_factory_make ("mad", "decoder");
  36.   if (mad == NULL)
  37.     {
  38.       g_print ("Failed to create mad element");
  39.       return -1;
  40.     }
  41.   audioconvert = gst_element_factory_make ("audioconvert", "converter");
  42.   if (audioconvert == NULL)
  43.     {
  44.       g_print ("Failed to create audioconvert element");
  45.       return -1;
  46.     }
  47.   alsasink = gst_element_factory_make ("alsasink", "sink");
  48.   if (alsasink == NULL)
  49.     {
  50.       g_print ("Failed to create alsasink element");
  51.       return -1;
  52.     }
  53.  
  54.   g_print ("Building pipeline...\n");
  55.   /* Add Elements to pipeline*/
  56.   pipeline = gst_pipeline_new ("mp3-pipeline");
  57.   gst_bin_add_many (GST_BIN (pipeline), filesrc, mad, audioconvert, alsasink, NULL);
  58.  
  59.   g_print ("Linking elements...\n");
  60.   /* Link Elements */
  61.   if (!gst_element_link_many (filesrc, mad, audioconvert, alsasink, NULL))
  62.     g_warning ("Failed to link elements!\n");
  63.  
  64.   /* Set filesrc location property */
  65.   if (argv[1] == NULL)
  66.     {
  67.       g_print ("mp3 file is not provided. usage: mp3player [file]\n");
  68.       return -1;
  69.     }
  70.   g_print ("Playing file: %s\n", argv[1]);
  71.   g_object_set (filesrc, "location", argv[1], NULL);
  72.  
  73.  
  74.   /* Set pipeline state to PLAYING */
  75.   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  76.  
  77.   /* Application loop (We'll use gtk_main() here soon) */
  78.   while (1)
  79.     {
  80.       g_usleep(G_USEC_PER_SEC);
  81.       g_print (".");
  82.     }
  83.  
  84.   return 0;
  85. }
RAW Paste Data
Top