[PATCH 14/17] grilo-test-ui.py: Added playback support



Used Gio introspection bindings to add playback support
---
 tools/python/grilo-test-ui.py |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/tools/python/grilo-test-ui.py b/tools/python/grilo-test-ui.py
index d76f00e..01df50d 100644
--- a/tools/python/grilo-test-ui.py
+++ b/tools/python/grilo-test-ui.py
@@ -2,6 +2,7 @@
 
 from gi.repository import Grl
 from gi.repository import Gtk
+from gi.repository import Gio
 from gi.repository import GdkPixbuf
 
 class MainWindow(Gtk.Window):
@@ -26,6 +27,7 @@ class MainWindow(Gtk.Window):
         self._ui_state = UIState()
         self.BROWSE_KEYS = self._lookup_browse_keys()
         self.METADATA_KEYS = self._lookup_metadata_keys()
+        self._launchers = UriLaunchers()
 
         self._setup_ui()
         self._load_plugins()
@@ -226,7 +228,31 @@ class MainWindow(Gtk.Window):
             self._remove_btn.set_sensitive(False)
 
     def _show_btn_clicked_cb(self, *args):
-        pass
+        if self._ui_state.last_url:
+            uri_list = []
+            print ('playing %(url)s' % {'url':self._ui_state.last_url})
+            uri_list.append(self._ui_state.last_url)
+
+            registry = Grl.PluginRegistry.get_default()
+            key_source = registry.lookup_metadata_key('source')
+            if isinstance(self._ui_state.cur_md_media, Grl.MediaImage):
+                app = self._launchers.eog
+            elif self._ui_state.cur_md_media.get(key_source) == 'grl-apple-trailers':
+                app = self._launchers.mplayer
+            else:
+                app = self._launchers.totem
+
+            try:
+                app.launch_uris(uri_list, None)
+            except:
+                print ('Cannot use %(app)s to show %(source)s; using default application' %
+                       {'app':app.get_name(),
+                        'source':self._ui_state.last_url})
+                try:
+                    app.launch_default_for_uri(self._ui_state.last_url, None)
+                except:
+                    print ('Cannot use default application to show %(source)s. Stopping playback' %
+                           {'source':self._ui_state.last_url})
 
     def _back_btn_clicked_cb(self, *args):
         pass
@@ -434,6 +460,19 @@ class MainWindow(Gtk.Window):
     def _quit(self, *args):
         Gtk.main_quit()
 
+class UriLaunchers(object):
+    def __init__(self):
+        self.eog = Gio.app_info_create_from_commandline('eog',
+                                                        'Eye of GNOME (eog)',
+                                                        Gio.AppInfoCreateFlags.SUPPORTS_URIS)
+        self.totem = Gio.app_info_create_from_commandline('totem',
+                                                          'Totem',
+                                                          Gio.AppInfoCreateFlags.SUPPORTS_URIS)
+        self.mplayer = Gio.app_info_create_from_commandline('mplayer -user-agent \"QuickTime\" -cache 5000',
+                                                            'The Movie Player (mplayer)',
+                                                            (Gio.AppInfoCreateFlags.SUPPORTS_URIS |
+                                                             Gio.AppInfoCreateFlags.NEEDS_TERMINAL))
+
 class UIState(object):
 
     def __init__(self, source_stack=[], container_stack=[], cur_source=None,
-- 
1.7.0.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]