2 // Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com>
6 using System.Runtime.InteropServices;
8 namespace GstreamerSharp
13 static Element Pipeline;
14 static GLib.MainLoop MainLoop;
16 public static void Main (string[] args)
18 // Initialize GStreamer
19 Application.Init (ref args);
22 Pipeline = Parse.Launch ("playbin uri=http://download.blender.org/durian/trailer/sintel_trailer-1080p.mp4");
23 var bus = Pipeline.Bus;
26 var ret = Pipeline.SetState (State.Playing);
27 if (ret == StateChangeReturn.Failure) {
28 Console.WriteLine ("Unable to set the pipeline to the playing state.");
30 } else if (ret == StateChangeReturn.NoPreroll) {
34 MainLoop = new GLib.MainLoop ();
36 bus.AddSignalWatch ();
37 bus.Message += HandleMessage;
42 Pipeline.SetState (State.Null);
45 static void HandleMessage (object o, MessageArgs args)
47 var msg = args.Message;
49 case MessageType.Error: {
53 msg.ParseError (out err, out debug);
54 Console.WriteLine ("Error: {0}", err.Message);
56 Pipeline.SetState (State.Ready);
62 Pipeline.SetState (State.Ready);
65 case MessageType.Buffering: {
68 // If the stream is live, we do not care about buffering.
71 percent = msg.ParseBuffering ();
72 Console.WriteLine ("Buffering ({0})", percent);
73 // Wait until buffering is complete before start/resume playing
75 Pipeline.SetState (State.Paused);
77 Pipeline.SetState (State.Playing);
80 case MessageType.ClockLost:
82 Pipeline.SetState (State.Paused);
83 Pipeline.SetState (State.Playing);