diff --git a/vg-hls.js b/vg-hls.js index a66ea26..672a268 100755 --- a/vg-hls.js +++ b/vg-hls.js @@ -21,7 +21,6 @@ angular.module("com.2fdevs.videogular.plugins.hls", []) restrict: "A", require: "^videogular", link: function (scope, elem, attr, API) { - var context; var player; var hlsTypeRegEx = /^application\/x-mpegURL/i; @@ -36,6 +35,7 @@ angular.module("com.2fdevs.videogular.plugins.hls", []) }; scope.onSourceChange = function onSourceChange(source) { + if (!source) return; var url = source.src; // It's HLS, we use Hls.js @@ -67,6 +67,7 @@ angular.module("com.2fdevs.videogular.plugins.hls", []) return API.sources; }, function (newVal/*, oldVal*/) { + if (!newVal) return; scope.onSourceChange(newVal[0]); } ); diff --git a/vg-hls.min.js b/vg-hls.min.js index f4ca9a7..616000e 100644 --- a/vg-hls.min.js +++ b/vg-hls.min.js @@ -1 +1 @@ -"use strict";angular.module("com.2fdevs.videogular.plugins.hls",[]).directive("vgHls",["$log",function($log){return{restrict:"A",require:"^videogular",link:function(scope,elem,attr,API){var player,hlsTypeRegEx=/^application\/x-mpegURL/i;Hls.isSupported()&&(scope.isHLS=function(source){var hasHlsType=hlsTypeRegEx.test(source.type),hasHlsExtension=source.src.indexOf&&source.src.indexOf(".m3u8")>0;return hasHlsType||hasHlsExtension},scope.onSourceChange=function(source){var url=source.src;if(scope.isHLS(source)){var video=API.mediaElement[0],hls=new Hls;hls.loadSource(url),hls.attachMedia(API.mediaElement[0]),hls.on(Hls.Events.MANIFEST_PARSED,function(){API.autoPlay&&video.play()})}else player&&(player.reset(),player=null,API.mediaElement.attr("src",url),API.stop())},scope.$watch(function(){return API.sources},function(newVal){scope.onSourceChange(newVal[0])}))}}}]); \ No newline at end of file +"use strict";angular.module("com.2fdevs.videogular.plugins.hls",[]).directive("vgHls",["$log",function($log){return{restrict:"A",require:"^videogular",link:function(scope,elem,attr,API){var player,hlsTypeRegEx=/^application\/x-mpegURL/i;Hls.isSupported()&&(scope.isHLS=function(source){var hasHlsType=hlsTypeRegEx.test(source.type),hasHlsExtension=source.src.indexOf&&source.src.indexOf(".m3u8")>0;return hasHlsType||hasHlsExtension},scope.onSourceChange=function(source){if(source){var url=source.src;if(scope.isHLS(source)){var video=API.mediaElement[0],hls=new Hls;hls.loadSource(url),hls.attachMedia(API.mediaElement[0]),hls.on(Hls.Events.MANIFEST_PARSED,function(){API.autoPlay&&video.play()})}else player&&(player.reset(),player=null,API.mediaElement.attr("src",url),API.stop())}},scope.$watch(function(){return API.sources},function(newVal){newVal&&scope.onSourceChange(newVal[0])}))}}}]); \ No newline at end of file