-
Notifications
You must be signed in to change notification settings - Fork 4
/
vg-hls.min.js
1 lines (1 loc) · 876 Bytes
/
vg-hls.min.js
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])}))}}}]);