All pastes #1435996 Raw Edit

Jemand

public text v1 · immutable
#1435996 ·published 2009-05-27 08:46 UTC
rendered paste body
using System;
using GLib;
using Gst;

public class Test
{
    private static MainLoop loop;
    private static string[] songs;
    private static int song_idx = 0;
    private static Pipeline pipeline;
    private static Element filesrc;

    static void onPadAdded (object o, PadAddedArgs args) {
      Element sink = Gst.ElementFactory.Make ("fakesink", null);

      pipeline.Add (sink);
      sink.SyncStateWithParent ();

      args.Pad.Link (sink.GetStaticPad ("sink"));
    }

    public static void Main (string[] args)
    {
        if (args.Length < 1) {
            Console.WriteLine ("usage: mono playbin-player.exe audio_file_uri");
            return;
        }

        songs = args;

        Gst.Application.Init ();
        loop = new MainLoop ();

	pipeline = new Pipeline ("pipeline");
	filesrc = ElementFactory.Make ("filesrc", "src");
	Element demux = ElementFactory.Make ("flvdemux", "demux");

	pipeline.Add (filesrc, demux);
	filesrc.Link (demux);

	demux.PadAdded += onPadAdded;

	Console.WriteLine ("Next file: " + songs[song_idx]);
	filesrc["location"] = args[0];

        pipeline.Bus.AddWatch (new BusFunc (BusCb));
        pipeline.SetState (State.Playing);
        
        loop.Run ();
    }

    private static bool BusCb (Bus bus, Message message)
    {
        switch (message.Type) {
            case MessageType.Error:
	    	Enum err;
                string msg;
                message.ParseError (out err, out msg);
                Console.WriteLine ("Gstreamer error: {0}", msg);
                loop.Quit ();
                break;
            case MessageType.Eos:
                if (song_idx + 1 >= songs.Length) {
                    Console.WriteLine ("Thank you, come again");
                    pipeline.SetState (State.Null);
                    loop.Quit ();
                } else {
                    pipeline.SetState (State.Null);

		    Gst.State s, p;

		    pipeline.GetState (out s, out p, Gst.Clock.TimeNone);

		    foreach (Element elt in pipeline.Elements) {
		      if (elt.Name.StartsWith ("fakesink"))
		        pipeline.Remove (elt);
		    }


                    filesrc["location"] = songs[++song_idx];

		    Console.WriteLine ("Next file: " + songs[song_idx]);
                    pipeline.SetState (State.Playing);
                }
                break;
        }

        return true;
    }
}