Added video player controls
authorThierry Florac <thierry.florac@onf.fr>
Thu, 20 Dec 2018 10:34:32 +0100
changeset 120 4f9400267849
parent 119 4cdacd1e34c7
child 121 313dcdc38ffb
Added video player controls
src/pyams_media/skin/resources/js/pyams_media.js
src/pyams_media/skin/resources/js/pyams_media.min.js
--- a/src/pyams_media/skin/resources/js/pyams_media.js	Thu Dec 20 09:57:21 2018 +0100
+++ b/src/pyams_media/skin/resources/js/pyams_media.js	Thu Dec 20 10:34:32 2018 +0100
@@ -2,17 +2,17 @@
 
 	"use strict";
 
-	var MyAMS = globals.MyAMS;
+	var ams = globals.MyAMS;
 
 	var PyAMS_media = {
 
 		initPlayer: function(element) {
-			MyAMS.ajax.check($.fn.flowplayer,
-							 '/--static--/pyams_media/flowplayer/flowplayer' + MyAMS.devext + '.js',
+			ams.ajax.check($.fn.flowplayer,
+							 '/--static--/pyams_media/flowplayer/flowplayer' + ams.devext + '.js',
 							 function(first_load) {
 								if (first_load) {
-									MyAMS.dialog.registerShownCallback(PyAMS_media.initPlayerDialog, player);
-									MyAMS.dialog.registerHideCallback(PyAMS_media.shutdownPlayerDialog, player);
+									ams.dialog && ams.dialog.registerShownCallback(PyAMS_media.initPlayerDialog, player);
+									ams.dialog && ams.dialog.registerHideCallback(PyAMS_media.shutdownPlayerDialog, player);
 								}
 								var player = $(element);
 								var flowplayer = player.flowplayer();
@@ -37,7 +37,9 @@
 		shutdownPlayerDialog: function() {
 			var dialog = $(this);
 			var player = $('.flowplayer', dialog).data('flowplayer');
-			player.shutdown();
+			if (player) {
+				player.shutdown();
+			}
 		},
 
 		getPlayerTime: function(/* e, api */) {
@@ -46,21 +48,23 @@
 				parent = $('.flowplayer', parent);
 			}
 			var player = parent.data('flowplayer');
-			var video = player.video;
-			if (!video.time && player.conf.flowplayer) {
-				video = player.conf.flowplayer.video;
-			}
-			if (video && video.time) {
-				var position = video.time;
-				var form = parent.parents('form');
-				$('INPUT[name="thumbnail_form.widgets.time"]', form).val(position);
+			if (player) {
+				var video = player.video;
+				if (!video.time && player.conf.flowplayer) {
+					video = player.conf.flowplayer.video;
+				}
+				if (video && video.time) {
+					var position = video.time;
+					var form = parent.parents('form');
+					$('INPUT[name="thumbnail_form.widgets.time"]', form).val(position);
+				}
 			}
 		},
 
 		pausePlayer: function() {
 			var form = $(this);
 			var player = $('.flowplayer', form).data('flowplayer');
-			if (player.playing) {
+			if (player && player.playing) {
 				player.pause();
 			}
 			PyAMS_media.getPlayerTime.call(form);
--- a/src/pyams_media/skin/resources/js/pyams_media.min.js	Thu Dec 20 09:57:21 2018 +0100
+++ b/src/pyams_media/skin/resources/js/pyams_media.min.js	Thu Dec 20 10:34:32 2018 +0100
@@ -1,1 +1,1 @@
-!function(o,a){"use strict";var n=a.MyAMS,y={initPlayer:function(t){n.ajax.check(o.fn.flowplayer,"/--static--/pyams_media/flowplayer/flowplayer"+n.devext+".js",function(a){a&&(n.dialog.registerShownCallback(y.initPlayerDialog,e),n.dialog.registerHideCallback(y.shutdownPlayerDialog,e));var e=o(t),l=e.flowplayer(),r=e.data("ams-flowplayer-events");if(r)for(var i in r)r.hasOwnProperty(i)&&l.on(i,n.getFunctionByName(r[i]))})},initPlayerDialog:function(){var a=o(this);o(".modal-viewport",a).removeAttr("style").removeClass("modal-viewport")},shutdownPlayerDialog:function(){var a=o(this);o(".flowplayer",a).data("flowplayer").shutdown()},getPlayerTime:function(){var a=o(this);a.hasClass("flowplayer")||(a=o(".flowplayer",a));var e=a.data("flowplayer"),l=e.video;if(!l.time&&e.conf.flowplayer&&(l=e.conf.flowplayer.video),l&&l.time){var r=l.time,i=a.parents("form");o('INPUT[name="thumbnail_form.widgets.time"]',i).val(r)}},pausePlayer:function(){var a=o(this),e=o(".flowplayer",a).data("flowplayer");return e.playing&&e.pause(),y.getPlayerTime.call(a),{}}};a.PyAMS_media=y}(jQuery,this);
+!function(a,e){"use strict";var l=e.MyAMS,i={initPlayer:function(e){l.ajax.check(a.fn.flowplayer,"/--static--/pyams_media/flowplayer/flowplayer"+l.devext+".js",function(r){r&&(l.dialog&&l.dialog.registerShownCallback(i.initPlayerDialog,o),l.dialog&&l.dialog.registerHideCallback(i.shutdownPlayerDialog,o));var o=a(e),t=o.flowplayer(),n=o.data("ams-flowplayer-events");if(n)for(var y in n)n.hasOwnProperty(y)&&t.on(y,MyAMS.getFunctionByName(n[y]))})},initPlayerDialog:function(){var e=a(this);a(".modal-viewport",e).removeAttr("style").removeClass("modal-viewport")},shutdownPlayerDialog:function(){var e=a(this),l=a(".flowplayer",e).data("flowplayer");l&&l.shutdown()},getPlayerTime:function(){var e=a(this);e.hasClass("flowplayer")||(e=a(".flowplayer",e));var l=e.data("flowplayer");if(l){var i=l.video;if(!i.time&&l.conf.flowplayer&&(i=l.conf.flowplayer.video),i&&i.time){var r=i.time,o=e.parents("form");a('INPUT[name="thumbnail_form.widgets.time"]',o).val(r)}}},pausePlayer:function(){var e=a(this),l=a(".flowplayer",e).data("flowplayer");return l&&l.playing&&l.pause(),i.getPlayerTime.call(e),{}}};e.PyAMS_media=i}(jQuery,this);