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

GstElement *Play(const char *src) {
  GstElement *playbin = gst_element_factory_make("playbin", "player");
  GstElement *videosink = gst_element_factory_make("fakesink", "fakevideo");
  g_object_set(G_OBJECT(playbin), "video-sink", videosink, NULL);
  GstElement *audiosink = gst_element_factory_make("autoaudiosink", "audiosink");
  g_object_set(G_OBJECT(playbin), "audio-sink", audiosink, NULL);
  g_object_set(G_OBJECT(playbin), "uri", src, NULL);
  gst_element_set_state(playbin, GST_STATE_PLAYING);
  return playbin;
}


int main(int argc, char *argv[]) {
  GstElement *playbin[4];
  int i;
  gst_init(&argc, &argv);

  char cwd[1024];
  char path[1024];
  getcwd(cwd, 1024);
  snprintf(path, 1024, "file://%s/test.mid", cwd);

  for (i = 0; i < 4; ++i) {
    playbin[i] = Play(path);
    sleep(2);
  }

  sleep(30);
  for (i = 0; i < 4; ++i) {
    gst_element_set_state(playbin[i], GST_STATE_NULL);
    gst_object_unref(GST_OBJECT(playbin[i]));
  }

  return 0;
}
