diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..ac2c971 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/node_modules/ +/bower_components/ +.idea \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100755 index 0000000..20e025c --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,48 @@ +module.exports = function(grunt) { + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + release: { + options: { + //bump: false, //default: true + //file: 'bower.json', //default: package.json + //add: false, //default: true + //commit: false, //default: true + //tag: false, //default: true + //push: false, //default: true + //pushTags: false, //default: true + //npmtag: true, //default: no tag + //folder: 'folder/to/publish/to/npm', //default project root + //commitMessage: 'check out my release <%= version %>', //default: 'release <%= version %>' + //tagMessage: 'tagging version <%= version %>', //default: 'Version <%= version %>', + //tagName: 'v<%= version %>', //default: '<%= version %>' + + file: 'bower.json', //default: package.json + add: false, //default: true + commit: false, //default: true + tag: false, //default: true + push: false, //default: true + pushTags: false, //default: true + npm: false + } + }, + uglify: { + options: { + mangle: false + }, + build: { + files: { + './vg-hls.min.js': ['./vg-hls.js'] + } + } + } + }); + + grunt.loadNpmTasks('grunt-release'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + + grunt.registerTask('major', ['release:major']); + grunt.registerTask('minor', ['release:minor']); + grunt.registerTask('patch', ['release:patch']); + + grunt.registerTask('build', ['uglify:build']); +}; diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..823b3f0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Pedro Sampaio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..87ead0a --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +bower-videogular-hls +===================== + +Videogular `HLS` plugin repository for distribution on `bower`. + +## Install + +Install [Videogular](http://www.videogular.com/) `hls` plugin with Bower: + +`bower install videogular-hls` + +### Install Videogular + +Install [Videogular](http://www.videogular.com/) with Bower: + +`bower install videogular` + +### Install themes + +Install [Videogular](http://www.videogular.com/) themes with Bower: + +`bower install videogular-themes-default` + +### Install plugins + +Install [Videogular](http://www.videogular.com/) plugins with Bower: + +`bower install videogular-buffering` + +`bower install videogular-overlay-play` + +`bower install videogular-controls` + +`bower install videogular-poster` + +## Documentation + +It's available on [Videogular's project Wiki](https://github.com/2fdevs/videogular/wiki). + +## License + +The MIT License (MIT) + +Copyright (c) 2014 Pedro Sampaio + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/bower.json b/bower.json new file mode 100755 index 0000000..694d20a --- /dev/null +++ b/bower.json @@ -0,0 +1,8 @@ +{ + "name": "videogular-hls", + "version": "1.0.0", + "main": "./vg-hls.js", + "dependencies": { + "videogular": "~1.4.0" + } +} diff --git a/index.js b/index.js new file mode 100755 index 0000000..d5f1f12 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +require('./vg-hls'); + +module.exports = 'com.2fdevs.videogular'; diff --git a/package.json b/package.json new file mode 100644 index 0000000..709e897 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "videogular-hls", + "version": "0.0.1", + "main": "index.js", + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-uglify": "^0.11.0", + "grunt-release": "~0.7.0" + }, + "engines": { + "node": ">=0.8.0" + } +} diff --git a/vg-hls.js b/vg-hls.js new file mode 100755 index 0000000..a66ea26 --- /dev/null +++ b/vg-hls.js @@ -0,0 +1,77 @@ +/** + * @ngdoc directive + * @name com.2fdevs.videogular.plugins.dash.directive:vgHls + * @restrict A + * @description + * Adds HLS support for vg-media. + * This plugin requires hls.js file available at hls.js project: + * https://github.com/dailymotion/hls.js + * + *
+ *+ * + */ +"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 context; + var player; + var hlsTypeRegEx = /^application\/x-mpegURL/i; + + //Proceed augmenting behavior only if the browser is capable of playing HLS + if(Hls.isSupported()) { + //Returns true if the source has the standard HLS type defined OR an .m3u8 extension. + scope.isHLS = function isHLS(source) { + var hasHlsType = hlsTypeRegEx.test(source.type); + var hasHlsExtension = source.src.indexOf && (source.src.indexOf(".m3u8") > 0); + + return hasHlsType || hasHlsExtension; + }; + + scope.onSourceChange = function onSourceChange(source) { + var url = source.src; + + // It's HLS, we use Hls.js + if (scope.isHLS(source)) { + var video = API.mediaElement[0]; + var hls = new Hls(); + hls.loadSource(url); + hls.attachMedia(API.mediaElement[0]); + hls.on(Hls.Events.MANIFEST_PARSED,function() { + if(API.autoPlay){ + video.play(); + } + }); + } + else if (player) { + //not HLS, but the Hls.js player is still wired up + //Dettach Hls.js from the mediaElement + player.reset(); + player = null; + + //player.reset() wipes out the new url already applied, so have to reapply + API.mediaElement.attr('src', url); + API.stop(); + } + }; + + scope.$watch( + function () { + return API.sources; + }, + function (newVal/*, oldVal*/) { + scope.onSourceChange(newVal[0]); + } + ); + } + } + } + } + ]); diff --git a/vg-hls.min.js b/vg-hls.min.js new file mode 100644 index 0000000..f4ca9a7 --- /dev/null +++ b/vg-hls.min.js @@ -0,0 +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+ * + *+ *