using System;
using GLib;
using Gst;

public class PlayBinPlayer
{
	static MainLoop loop;

	public static void Main (string[] args)
	{
		Application.Init();
		loop = new MainLoop();

		Element pipeline = Parse.Launch("fakesrc ! fakesink");


		pipeline.Bus.AddWatch(new BusFunc(BusCb));
		//pipeline.Bus.AddSignalWatch();
		//pipeline.Bus.Message += delegate (object o, MessageArgs margs) {BusCb(null, margs.Message);};


		pipeline.SetState(State.Playing);
		loop.Run();
	}

	private static bool BusCb (Bus bus, Message message)
	{
		if (message.Type == MessageType.StateChanged) {
			Console.Write("Message from {0}:  \t{1}", message.Src.Name, message.Type);
			State oldstate, newstate, pending;
			message.ParseStateChanged(out oldstate, out newstate, out pending);
			Console.WriteLine("\t\t{0} -> {1}   ({2})", oldstate, newstate, pending);
			if (newstate == State.Playing && message.Src is Pipeline) {
				Console.WriteLine("OK");
				loop.Quit();
			}
		}
		else
			Console.WriteLine("Message from {0}:  \t{1}", message.Src.Name, message.Type);
		return true;
	}
}

