Added video thumbnail
authorThierry Florac <thierry.florac@onf.fr>
Wed, 20 Sep 2017 14:05:49 +0200
changeset 56 44f79a6a9033
parent 55 3bff9e2b8533
child 57 7de6abf4258d
Added video thumbnail
src/pyams_media/zmi/templates/video-preview.pt
src/pyams_media/zmi/video.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_media/zmi/templates/video-preview.pt	Wed Sep 20 14:05:49 2017 +0200
@@ -0,0 +1,24 @@
+<div class="flowplayer"
+	 data-ams-plugins="flowplayer"
+	 data-ams-plugin-flowplayer-async="false"
+	 data-ams-callback="PyAMS_media.initPlayer"
+	 tal:attributes="data-ams-plugin-flowplayer-src extension:resource_path('pyams_media.skin:flowplayer');
+					 data-ams-plugin-flowplayer-css extension:resource_path('pyams_media.skin:functional_css');
+					 data-ams-callback-source extension:resource_path('pyams_media.skin:pyams_media');">
+	<video
+		tal:define="href extension:absolute_url(context);
+					thumbnails extension:thumbnails(context);
+					conversions extension:conversions(context);
+					size thumbnails.get_image_size();"
+		tal:attributes="poster string:${href}/++thumb++${size[0]}x${size[1]}.png">
+		<tal:loop repeat="conversion conversions.get_conversions(order=('video/webm','video/mp4','video/x-flv'))">
+			<source type="video/mp4"
+					tal:define="media_width conversions.get_conversion_width(conversion.__name__);
+								video_type extension:video_type(conversion);"
+					tal:condition="video_type"
+					tal:attributes="type video_type;
+									src extension:absolute_url(conversion);
+									media 'all and (max-width: {0}px)'.format(media_width) if media_width else None;" />
+		</tal:loop>
+	</video>
+</div>
--- a/src/pyams_media/zmi/video.py	Wed Sep 20 14:05:34 2017 +0200
+++ b/src/pyams_media/zmi/video.py	Wed Sep 20 14:05:49 2017 +0200
@@ -20,7 +20,7 @@
 from pyams_file.interfaces import IVideo, IThumbnail
 from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager, IFormHelp
 from pyams_skin.interfaces.viewlet import IContextActions
-from pyams_utils.interfaces import MANAGE_PERMISSION
+from pyams_utils.interfaces import MANAGE_PERMISSION, VIEW_PERMISSION
 from pyams_zmi.layer import IAdminLayer
 from z3c.form.interfaces import HIDDEN_MODE
 
@@ -35,7 +35,7 @@
 from pyams_utils.adapter import adapter_config
 from pyams_utils.schema import DottedDecimalField
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
-from pyams_zmi.form import AdminDialogAddForm
+from pyams_zmi.form import AdminDialogAddForm, AdminDialogDisplayForm
 from pyramid.view import view_config
 from z3c.form import field, button
 from zope.interface import Interface
@@ -44,6 +44,27 @@
 
 
 #
+# Video preview
+#
+
+@pagelet_config(name='preview.html', context=IVideo, layer=IPyAMSLayer, permission=VIEW_PERMISSION)
+class VideoPreview(AdminDialogDisplayForm):
+    """Video preview"""
+
+    label = _("Video preview")
+    label_css_class = 'fa fa-fw fa-film'
+
+    fields = field.Fields(Interface)
+
+
+@viewlet_config(name='video-preview-prefix', context=IVideo, layer=IAdminLayer, view=VideoPreview,
+                manager=IWidgetsPrefixViewletsManager)
+@template_config(template='templates/video-preview.pt')
+class VideoPreviewViewletsPrefix(Viewlet):
+    """Video preview viewlets prefix"""
+
+
+#
 # Video thumbnail
 #