examples: python: Simplify the simple example
authorThibault Saunier <tsaunier@igalia.com>
Tue, 18 May 2021 15:16:02 +0000 (11:16 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 21 May 2021 21:26:19 +0000 (21:26 +0000)
We shouldn't show assets usage in the simplest example we have
as it is useful for more advanced use cases.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/252>

examples/python/gst-player.py
examples/python/simple.py

index 7cb2ae5..51ba739 100755 (executable)
@@ -1,3 +1,4 @@
+#!/usr/bin/python3
 import sys
 import gi
 
index 1de9f6e..7874e97 100755 (executable)
@@ -31,22 +31,17 @@ from gi.repository import Gst, GES, GLib  # noqa
 class Simple:
     def __init__(self, uri):
         timeline = GES.Timeline.new_audio_video()
-        self.project = timeline.get_asset()
-
-        self.project.connect("asset-added", self._asset_added_cb)
-        self.project.connect("error-loading-asset", self._error_loading_asset_cb)
-        self.project.create_asset(uri, GES.UriClip)
-        self.layer = timeline.append_layer()
-        self._create_pipeline(timeline)
-        self.loop = GLib.MainLoop()
-
-    def _create_pipeline(self, timeline):
-        self.pipeline = GES.Pipeline()
-        self.pipeline.set_timeline(timeline)
-        bus = self.pipeline.get_bus()
+        layer = timeline.append_layer()
+        layer.add_clip(GES.UriClip.new(uri))
+        self.pipeline = pipeline = GES.Pipeline()
+        pipeline.set_timeline(timeline)
+        pipeline.set_state(Gst.State.PLAYING)
+        bus = pipeline.get_bus()
         bus.add_signal_watch()
         bus.connect("message", self.bus_message_cb)
 
+        self.loop = GLib.MainLoop()
+
     def bus_message_cb(self, unused_bus, message):
         if message.type == Gst.MessageType.EOS:
             print("eos")
@@ -59,14 +54,6 @@ class Simple:
     def start(self):
         self.loop.run()
 
-    def _asset_added_cb(self, project, asset):
-        self.layer.add_asset(asset, 0, 0, Gst.SECOND * 5, GES.TrackType.UNKNOWN)
-        self.pipeline.set_state(Gst.State.PLAYING)
-
-    def _error_loading_asset_cb(self, project, error, asset_id, type):
-        print("Could not load asset %s: %s" % (asset_id, error))
-        self.loop.quit()
-
 if __name__ == "__main__":
     if len(os.sys.argv) != 2:
         print("You must specify a file URI")