Пример #1
0
        public static void Main(string[] args)
        {
            // Initialize Gstreamer
            Application.Init(ref args);

            // Create the elements
            playbin = ElementFactory.Make ("playbin", "playbin");

            if (playbin == null) {
                Console.WriteLine ("Not all elements could be created");
                return;
            }

            // Set the URI to play.
            playbin ["uri"] = "http://download.blender.org/durian/trailer/sintel_trailer-1080p.mp4";

            // Start playing
            var ret = playbin.SetState (State.Playing);
            if (ret == StateChangeReturn.Failure) {
                Console.WriteLine ("Unable to set the pipeline to the playing state.");
                return;
            }

            // Listen to the bus
            var bus = playbin.Bus;
            do {
                var msg = bus.TimedPopFiltered (100 * Constants.MSECOND, MessageType.StateChanged | MessageType.Error |  MessageType.DurationChanged);

                // Parse message
                if (msg != null) {
                    HandleMessage (msg);
                }
                else {
                    // We got no message, this means the timeout expired
                    if (playing) {
                        var fmt = Format.Time;
                        var current = -1L;

                        // Query the current position of the stream
                        if (!playbin.QueryPosition (fmt, out current)) {
                            Console.WriteLine ("Could not query current position.");
                        }

                        // if we didn't know it yet, query the stream position
                        if (duration <= 0) {
                            if (!playbin.QueryDuration (fmt, out duration)) {
                                Console.WriteLine ("Could not query current duration.");
                            }
                        }

                        // Print current position and total duration
                        Console.WriteLine ("Position {0} / {1}", new TimeSpan (current), new TimeSpan (duration));

                        if (seekEnabled && seekDone && current > 10L * Constants.SECOND) {
                            Console.WriteLine ("Readed 10s, performing seek...");
                            playbin.SeekSimple (fmt, SeekFlags.KeyUnit, 30L * Constants.SECOND);
                            seekDone = true;
                        }
                    }
                }
            } while (!terminate);
        }