summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorStephan Sundermann <ssundermann@gnome.org>2014-08-07 18:48:04 +0200
committerStephan Sundermann <ssundermann@gnome.org>2014-08-07 18:48:04 +0200
commit346893cc105253d42a84e94a809d06ec9927774b (patch)
tree7e49589c1236c1c014f79659207c69472aa5bb65 /samples
parentf58721c84acb1b9fab5bc2a818323d3a21f4fd01 (diff)
sample: Add basic tutorial 12 sample
Diffstat (limited to 'samples')
-rw-r--r--samples/BasicTutorial12.cs91
-rw-r--r--samples/Makefile.am8
2 files changed, 97 insertions, 2 deletions
diff --git a/samples/BasicTutorial12.cs b/samples/BasicTutorial12.cs
new file mode 100644
index 0000000..5eb572a
--- /dev/null
+++ b/samples/BasicTutorial12.cs
@@ -0,0 +1,91 @@
+// Authors
+// Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com>
+
+using System;
+using Gst;
+using System.Runtime.InteropServices;
+
+namespace GstreamerSharp
+{
+ class Playback
+ {
+ static bool IsLive;
+ static Element Pipeline;
+ static GLib.MainLoop MainLoop;
+
+ public static void Main (string[] args)
+ {
+ // Initialize GStreamer
+ Application.Init (ref args);
+
+ // Build the pipeline
+ Pipeline = Parse.Launch ("playbin uri=http://download.blender.org/durian/trailer/sintel_trailer-1080p.mp4");
+ var bus = Pipeline.Bus;
+
+ // Start playing
+ var ret = Pipeline.SetState (State.Playing);
+ if (ret == StateChangeReturn.Failure) {
+ Console.WriteLine ("Unable to set the pipeline to the playing state.");
+ return;
+ } else if (ret == StateChangeReturn.NoPreroll) {
+ IsLive = true;
+ }
+
+ MainLoop = new GLib.MainLoop ();
+
+ bus.AddSignalWatch ();
+ bus.Message += HandleMessage;
+
+ MainLoop.Run ();
+
+ // Free resources
+ Pipeline.SetState (State.Null);
+ }
+
+ static void HandleMessage (object o, MessageArgs args)
+ {
+ var msg = args.Message;
+ switch (msg.Type) {
+ case MessageType.Error: {
+ GLib.GException err;
+ string debug;
+
+ msg.ParseError (out err, out debug);
+ Console.WriteLine ("Error: {0}", err.Message);
+
+ Pipeline.SetState (State.Ready);
+ MainLoop.Quit ();
+ break;
+ }
+ case MessageType.Eos:
+ // end-of-stream
+ Pipeline.SetState (State.Ready);
+ MainLoop.Quit ();
+ break;
+ case MessageType.Buffering: {
+ int percent = 0;
+
+ // If the stream is live, we do not care about buffering.
+ if (IsLive) break;
+
+ percent = msg.ParseBuffering ();
+ Console.WriteLine ("Buffering ({0})", percent);
+ // Wait until buffering is complete before start/resume playing
+ if (percent < 100)
+ Pipeline.SetState (State.Paused);
+ else
+ Pipeline.SetState (State.Playing);
+ break;
+ }
+ case MessageType.ClockLost:
+ // Get a new clock
+ Pipeline.SetState (State.Paused);
+ Pipeline.SetState (State.Playing);
+ break;
+ default:
+ // Unhandled message
+ break;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/samples/Makefile.am b/samples/Makefile.am
index 81d2a22..0dc6c37 100644
--- a/samples/Makefile.am
+++ b/samples/Makefile.am
@@ -1,4 +1,4 @@
-TARGETS = playback.exe video-overlay.exe basic-tutorial-1.exe basic-tutorial-2.exe basic-tutorial-3.exe basic-tutorial-4.exe basic-tutorial-5.exe basic-tutorial-6.exe basic-tutorial-7.exe basic-tutorial-8.exe basic-tutorial-9.exe
+TARGETS = playback.exe video-overlay.exe basic-tutorial-1.exe basic-tutorial-2.exe basic-tutorial-3.exe basic-tutorial-4.exe basic-tutorial-5.exe basic-tutorial-6.exe basic-tutorial-7.exe basic-tutorial-8.exe basic-tutorial-9.exe basic-tutorial-12.exe
DEBUGS = $(addsuffix .mdb, $(TARGETS))
assemblies = \
@@ -42,6 +42,9 @@ basic-tutorial-8.exe: $(srcdir)/BasicTutorial8.cs $(assemblies)
basic-tutorial-9.exe: $(srcdir)/BasicTutorial9.cs $(assemblies)
$(CSC) $(CSFLAGS) -out:basic-tutorial-9.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/BasicTutorial9.cs
+basic-tutorial-12.exe: $(srcdir)/BasicTutorial12.cs $(assemblies)
+ $(CSC) $(CSFLAGS) -out:basic-tutorial-12.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/BasicTutorial12.cs
+
EXTRA_DIST = \
Playback.cs \
VideoOverlay.cs \
@@ -53,4 +56,5 @@ EXTRA_DIST = \
BasicTutorial6.cs \
BasicTutorial7.cs \
BasicTutorial8.cs \
- BasicTutorial9.cs
+ BasicTutorial9.cs \
+ BasicTutorial12.cs