Playbin and name

In the following example, the MP3 is played. Note the ! volume . The volume is not actually needed.

// gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0 gstreamer-audio-1.0`

#include <stdio.h>
#include <gst/gst.h>

int main (int argc, char *argv[]) {
  gst_init (&argc, &argv); 

  GstElement * pipeline = gst_parse_launch("playbin name=bin ! volume", NULL);
//  GstElement * pipeline = gst_parse_launch("playbin name=bin", NULL);
  if (!pipeline) {
    printf("pipeline error\n");
  }

  GstElement * bin = gst_bin_get_by_name(GST_BIN(pipeline), "bin");
  if (!bin) {
    printf("bin error\n");
  }

  g_object_set(bin, "uri", "file:/home/tux/Schreibtisch/sound/test.mp3", NULL);

  gst_element_set_state(pipeline, GST_STATE_PLAYING);
  printf("<CTRL+C> = stop\n");
  while (1) {  }

  gst_object_unref(pipeline);
}

In the following example, the MP3 is played. Note the ! volume . The volume is not actually needed.

GstElement * pipeline = gst_parse_launch("playbin name=bin", NULL);

Now the strange thing is, if I leave out the ! volume, gst_bin_get_by_name(GST_BIN(pipeline), "bin") is NULL.

Why is this?
Shouldn’t name also work without the volume?

I can’t tell why it fails in such way (or doesn’t in the former case), though you may workaround this issue using correct uri for your file (file:// + absolute_path_to_file):

g_object_set(bin, "uri", "file:///home/tux/Schreibtisch/sound/test.mp3", NULL);

I can’t call g_object_set because bin is nil.

Sorry for my previous advice, seems stupid to me now :crazy_face:

Seems that when the pipeline only has one element, the pipeline is this element, So you already have the pointer to playbin with the pointer to pipeline and may be able to set uri from this.

playbin is a pipeline. Just use it alone.

Asking gst_parse_launch to create something with playbin and something else will result in … a pipeline containing a pipeline and a random element.

Just create playbin, you can then just use it as-is (a pipeline is a bin is an element).

1 Like