Commits

shuerhaaken committed ba69867

add some code examples

Comments (0)

Files changed (5)

examples/EXAMPLES NOT DONE

Empty file removed.

examples/SOME EXAMPLES NOT DONE

Empty file added.

examples/tagreader.vala

+using TagInfo;
+
+void main() {
+    Info info = Info.factory_make("/path/to/file.ogg");
+    info.read();
+    string tit = info.title;
+    print("title: %s\n", tit);
+    print("album: %s\n", info.album);
+    print("artist: %s\n", info.artist);
+    print("albumartist: %s\n", info.albumartist);
+    return;
+}

examples/tagreader_img.vala

+using TagInfo;
+
+
+void main(string[] args) {
+    Gtk.init(ref args);
+    Info info = Info.factory_make("/path/to/file.flac");
+    if(!info.read()) {
+        print("error read\n");
+        return;
+    }
+    Gdk.Pixbuf pixbuf = null;
+    uint8[] data = null;
+    if(!info.get_image(out data)) {
+        print("error 0\n");
+        return;
+    }
+    assert(data != null);
+    var pbloader = new Gdk.PixbufLoader();
+    try {
+        uint8[] idata = (uint8[])data;
+        idata.length = data.length;
+        pbloader.write(idata);
+    }
+    catch(Error e) {
+        print("Error 1: %s\n", e.message);
+        try { pbloader.close(); } catch(Error e) { print("Error 2\n");}
+        return;
+    }
+    try { pbloader.close(); } catch(Error e) {}
+    pixbuf = pbloader.get_pixbuf();
+    assert(pixbuf != null);
+    
+    Gtk.Image image = new Gtk.Image.from_pixbuf(pixbuf);
+    var win = new Gtk.Window();
+    win.add(image);
+    win.show_all();
+    win.destroy.connect(Gtk.main_quit);
+    Gtk.main();
+    return;
+}

examples/tagwriter_img.vala

+using TagInfo;
+
+
+void main(string[] args) {
+    Info info = Info.factory_make("path/to/file.mp3");
+    if(!info.read()) {
+        print("error read\n");
+        return;
+    }
+    Gdk.Pixbuf pixbuf = new Gdk.Pixbuf.from_file("/path/to/image.jpeg");
+    assert(pixbuf != null);
+    uint8[] data;
+    try {
+        pixbuf.save_to_buffer(out data, "jpeg");
+    }
+    catch(Error e) {
+        print("%s\n", e.message);
+    }
+    if(!info.set_image(data, ImageType.UNKNOWN)) {
+        print("error 0\n");
+        return;
+    }
+    info.write();
+}