changeset 1346:cda5537c71d6

browser (photos/album): videos integrations: videos can now be added to an album, the alternative media player is then used to display them. Slides options are used to remove pagination and slidebar from slideshow (they don't play well with media player), and video are reset when its slide is exited.
author Goffi <goffi@goffi.org>
date Tue, 25 Aug 2020 08:31:56 +0200
parents ce1217e3a9c0
children 48e2a8b07c0b
files libervia/pages/photos/album/_browser/__init__.py
diffstat 1 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/pages/photos/album/_browser/__init__.py	Tue Aug 25 08:28:08 2020 +0200
+++ b/libervia/pages/photos/album/_browser/__init__.py	Tue Aug 25 08:31:56 2020 +0200
@@ -5,6 +5,7 @@
 import dialog
 from slideshow import SlideShow
 from invitation import InvitationManager
+import alt_media_player
 
 cache_path = window.cache_path
 files_service = window.files_service
@@ -15,6 +16,11 @@
     pass
 bridge = Bridge()
 
+alt_media_player.install_if_needed()
+
+photo_tpl = Template('photo/item.html')
+player_tpl = Template('components/media_player.html')
+
 # file upload
 
 def on_progress(ev, photo_elt):
@@ -65,7 +71,6 @@
 
 def upload_files(files):
     print(f"uploading {len(files)} files")
-    photo_tpl = Template('photo/item.html')
     album_items = document['album_items']
     for file_ in files:
         url = window.URL.createObjectURL(file_)
@@ -180,8 +185,25 @@
             thumb_url = f"{cache_path}{biggest_thumb['filename']}"
         except (KeyError, IndexError) as e:
             print(f"Can't get full screen thumbnail URL: {e}")
-            thumb_url = item['url']
-        slideshow.add_slide(html.IMG(src=thumb_url, Class="slide_img"), item)
+            thumb_url = None
+        if item.get("mime_type", "")[:5] == "video":
+            player = alt_media_player.MediaPlayer(
+                [item['url']],
+                poster = thumb_url,
+                reduce_click_area =  True
+            )
+            elt = player.elt
+            elt.classList.add("slide_video", "no_fullscreen")
+            slideshow.add_slide(
+                elt,
+                item,
+                options={
+                    "flags": (alt_media_player.NO_PAGINATION, alt_media_player.NO_SCROLLBAR),
+                    "exit_callback": player.reset,
+                }
+            )
+        else:
+            slideshow.add_slide(html.IMG(src=thumb_url or item['url'], Class="slide_img"), item)
         if item_elt == clicked_item_elt:
             slideshow.index = idx