[Rhythmbox-devel] How does Rhymthbox import songs into GtkTreeView without playing them?



Hello everybody,

I am currently practicing programming by writing a small music manager in GTK+ and C. I spent the last two weeks reading Rhymthbox's source code trying to figure out how to make my music manager software imports the songs without playing them. Here is what I tried:

void import_media_activated(GtkMenuItem *item, GtkTreeView *treeview) {
  GtkWidget *dialog;
  GSList *fileuris, *filenames;
  GstElement *fakeplay;
  GstTagList *taglist = NULL;
  GstMessage *msg;
  const gchar *tag;
  gint result;
  
  dialog = gtk_file_chooser_dialog_new("Import File(s)...", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
  
  gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
  
  if (result == GTK_RESPONSE_OK) {
    fileuris = gtk_file_chooser_get_uris(GTK_FILE_CHOOSER(dialog));
  }
  
  while (fileuris != NULL) {
    fakeplay = gst_element_factory_make("playbin", "fakeplay");
    g_object_set(G_OBJECT(fakeplay), "uri", fileuris->data, NULL);
    gst_element_set_state(fakeplay, GST_STATE_PAUSED);
  
    msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS(fakeplay), GST_CLOCK_TIME_NONE, GST_MESSAGE_TAG);
  
    gst_message_parse_tag(msg, &taglist);
  
    gchar* fileuri = (gchar*) fileuris->data;
  
    insert_tag_on_mb_treeview(taglist, GTK_TREE_VIEW(mb_treeview), g_filename_from_uri(fileuri, NULL, NULL));
  
    fileuris = fileuris->next;
  
    gst_message_unref(msg);
  }
  
  gtk_widget_destroy(dialog);
  gst_element_set_state(fakeplay, GST_STATE_NULL);
  gst_object_unref(fakeplay);
}

Basically I just created a playbin with each song, set its state to GST_STATE_PAUSED and then get the GstTagList from the GstMessage of the playbin. 

However, this method is pretty resource-consuming and slow, especially when I import like 1000+ songs (it crashed). 

Therefore, I am just curious to know how the Rhythmbox team imported all the songs without playing them? In other words, do you guys also set the song's state to GST_STATE_PAUSED to import them, or do you use another way?

Thank you for reading my message!! I love using Rhythmbox and it really inspired my small personal software!!

Have a good day!!


Best regards,

Phong Cao


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]