/*!

* sense-media-box - Include web pages, videos, images and much more into your Qlik Sense app.
* --
* @version v0.4.3
* @link https://github.com/stefanwalther/sense-media-box
* @author Stefan Walther
* @license MIT
*/

/*global define*/
define(["qvangular","./../../js/extUtils","text!./qsMbVideo.ng.html","text!./videojs.min.css","./videojs.min"],function(qvangular,extUtils,ngTemplate,videojsCss){"use strict";qvangular.directive("qsMbVideo",function(){return extUtils.addStyleToHeader(videojsCss),{restrict:"E",template:ngTemplate,scope:{objectId:"=",videoType:"=",videoSourceMp4:"=",videoSourceVimeo:"=",videoPoster:"="},link:function($scope,$element){function getSource(){return $scope.videoSourceMp4}function getTechOrder(){switch($scope.videoType){case"video/mp4":return["html5"];default:return["html5"]}}function configVideo(){var options={techOrder:getTechOrder(),controls:!0,autoplay:!1,preload:"auto",poster:$scope.videoPoster},videoSource=getSource();videoSource&&(player?player.src({type:$scope.videoType,src:getSource()}):player=videojs($element.find("video")[0],options,function(){var mPlayer=this;mPlayer.src({type:$scope.videoType,src:getSource()})}))}var player;$scope.$on("$destroy",function(){player&&player.dispose()}),$scope.$watchCollection("[videoType, videoSourceMP4, videoSourceVimeo]",function(newVal){configVideo()})}}})});