summaryrefslogtreecommitdiff
path: root/samples/BasicTutorial2.cs
diff options
context:
space:
mode:
authorStephan Sundermann <ssundermann@gnome.org>2014-08-01 16:15:22 +0200
committerStephan Sundermann <ssundermann@gnome.org>2014-08-01 16:15:22 +0200
commit27d42dfd3fe0ec459890fb7ad70fde4439fb5004 (patch)
tree5ede705e2814be36751ef65097f46dece0bbe192 /samples/BasicTutorial2.cs
parent2e8045d2dced260c2e000d0ef5a0cf3b051006dc (diff)
sample: Add basic tutorial 2 sample
Diffstat (limited to 'samples/BasicTutorial2.cs')
-rw-r--r--samples/BasicTutorial2.cs77
1 files changed, 77 insertions, 0 deletions
diff --git a/samples/BasicTutorial2.cs b/samples/BasicTutorial2.cs
new file mode 100644
index 0000000..4f68182
--- /dev/null
+++ b/samples/BasicTutorial2.cs
@@ -0,0 +1,77 @@
+// Authors
+// Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com>
+
+using System;
+using Gst;
+
+namespace GstreamerSharp
+{
+ class Playback
+ {
+ public static void Main (string[] args)
+ {
+ // Initialize Gstreamer
+ Application.Init(ref args);
+
+ // Build the pipeline
+ var source = ElementFactory.Make ("videotestsrc", "source");
+ var sink = ElementFactory.Make ("autovideosink", "sink");
+
+ // Create the empty pipeline
+ var pipeline = new Pipeline ("test-pipeline");
+
+ if (pipeline == null || source == null || sink == null) {
+ Console.WriteLine ("Not all elements could be created");
+ return;
+ }
+
+ // Build the pipeline
+ pipeline.Add (source, sink);
+ if (!source.Link (sink)) {
+ pipeline.Dispose ();
+ Console.WriteLine ("Elements could not be linked");
+ return;
+ }
+
+ // Modify the source's properties
+ source ["pattern"] = 0;
+
+ // Start playing
+ var ret = pipeline.SetState(State.Playing);
+ if (ret == StateChangeReturn.Failure) {
+ Console.WriteLine ("Unable to set the pipeline to the playing state");
+ pipeline.Dispose ();
+ return;
+ }
+
+ // Wait until error or EOS
+ var bus = pipeline.Bus;
+ var msg = bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error);
+
+ // Free resources
+ if (msg != null) {
+ switch (msg.Type) {
+ case MessageType.Error:
+ GLib.GException exc;
+ string debug;
+ msg.ParseError (out exc, out debug);
+ Console.WriteLine (String.Format ("Error received from element {0}: {1}", msg.Src.Name, exc.Message));
+ Console.WriteLine (String.Format ("Debugging information {0}", debug));
+ break;
+ case MessageType.Eos:
+ Console.WriteLine ("End-Of-Stream reached");
+ break;
+ default:
+ // We should not reach here because we only asked for ERRORs and EOS
+ Console.WriteLine ("Unexpected messag received");
+ break;
+ }
+ msg.Dispose ();
+ }
+
+ bus.Dispose ();
+ pipeline.SetState (State.Null);
+ pipeline.Dispose ();
+ }
+ }
+} \ No newline at end of file