hi folks,

before i get to bed, i wanted to share this little example of gstreamer
states and tags, maybe someone finds it useful (or has some
additions/corrections).

good night
osku

ps. is it "normal" that i get:

In function ‘bus_callback’:
86: warning: passing argument 2 of ‘gst_tag_list_foreach’ from
incompatible pointer type

when compiling?
// -*- tab-width: 4 -*-
/*
valac --pkg gstreamer-0.10 stream_states_and_tags.vala
./stream_states_and_tags http://scfire-dtc-aa06.stream.aol.com:80/stream/1018
*/

using Gst;

dynamic Gst.Element play_src;

void foreach_tag (Gst.TagList list, string tag) {

	GLib.Value tag_string = GLib.Value(typeof(string));
	GLib.Value foobar = list.get_value_index (tag, 0);
	foobar.transform(ref tag_string);
	stdout.printf ("got tag: %s=%s\n", tag, tag_string.get_string());

}

bool bus_callback (Gst.Bus bus, Gst.Message message) {

	GLib.Error err;
	string debug;

	Gst.State oldstate;
	Gst.State newstate;
	Gst.State penstate;
	Gst.TagList tag_list;

	switch (message.type) {

		case Gst.MessageType.ERROR:
			play_src.set_state (State.NULL);
			message.parse_error (out err, out debug);
			stdout.printf ("Error: %s\n", err.message);
			break;

		case Gst.MessageType.TAG:
			message.parse_tag (out tag_list);
			tag_list.foreach (foreach_tag);
			break;

		case Gst.MessageType.STATE_CHANGED:
			message.parse_state_changed (
									 out oldstate, out newstate, out penstate);
			stdout.printf ("state changed: %s>%s|%s\n", 
														oldstate.to_string(), 
														newstate.to_string(), 
														penstate.to_string());
			break;

		default:
			stdout.printf ("unhandled state: %s\n", 
													message.type.to_string());
			break;
	}

	return true;

}



public static int main (string[] args) {

	if (args.length <= 1) {
		stdout.printf ("Usage: %s <url to audio stream>\n", args[0]);
		return 1;
	}

	Gst.init (ref args);
	Gst.Bus bus;

	play_src = Gst.ElementFactory.make ("playbin", "play_src");
	bus = play_src.get_bus ();
	bus.add_watch (bus_callback);

	play_src.uri = args[1];
	play_src.set_state (State.PLAYING);

    var loop = new MainLoop (null, false);
    loop.run ();

	return 0;

}

// vim:tabstop=4:

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to