• Stars
    star
    227
  • Rank 175,900 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Modularised ~13KB HTML5 audio/video implementation using Angular.js

ngVideo

Travis ย  npm ย  License MIT


ngVideo is a HTML5 video player written in Angular.js.

ngVideo 0.3.2

ngVideo utilises Angular.js directives extensively which compartmentalises the various components that make-up the overall ngVideo experience โ€“ meaning you get to pick and choose which components you wish to utilise.

Directive Requirements

When using ngVideo, the only required directive is the main ng-video directive which handles all of the core logic, as well as the vi-screen directive which is the player itself. All other directives are optional.

Getting Started

Terminology: When we mention videoModel we mean the object that is returned from addSource/save.

Starting to use ngVideo is a breeze! Firstly you must define the container which will contain your video node.

<section class="video" ng-video>

Note: You can load multi-sources for each video for fallback purposes with multiSource.

You then need to fulfill the only other requirement for ngVideo โ€“ the video node:

<video vi-screen></video>

After that you have all that's necessary to begin playing videos โ€“ albeit without any user control.

ngVideo ships with a simple service that can be injected into your controllers, directives, services, et cetera... Since the video service is what's used for adding video sources, we'll inject video into one of our controllers:

myApp.controller('VideoController', ['$scope', 'video', function($scope, video) {

    /* Controller... */
    
}]);

We can then subsequently add video sources to be played. For this grab yourself a valid video source and add it:

video.addSource('mp4', 'http://www.example.com/alice-in-wonderland.mp4');

At this point you should notice that the video is visible in the player, but not actually playing โ€“ unless you specify the autoplay attribute on the video node โ€“ for the user to begin playing the video, you need to add the vi-controls directive.


Multi Source

Not all browsers support the same media types, and therefore ngVideo comes bundled with a way to load multiple source types for each of your videos โ€“ ngVideo will attempt to play the first video in the source collection, and if unsupported, move to the next one, and so on.

var source = video.multiSource();
source.addSource('mp4', 'http://www.example.com/master-and-margarita.mp4');
source.addSource('ogg', 'http://www.example.com/master-and-margarita.ogg');
source.save();

Once you invoke the save method, the video will be either played, or added to the playlist for later.


Directives

  • Buffer: Buffered segments of video;
  • Controls: Play and pause buttons;
  • Feedback: Real-time video data;
  • Full Screen: Open player in full screen;
  • Meta: Reading meta data from videos;
  • Messages: Subscribes to various video callbacks;
  • Playback Rate: Adjusting the playback;
  • Playlist: Managing a video/audio playlist;
  • Seekable: Update the player's current time;
  • Screen: Appending the screen element;
  • Timeline: input representing current time;
  • Volume: Managing the volume control;

Buffer

With the buffer directive you can display a bar similar to the timeline which displays the buffered segments of the video โ€“ using the canvas element.

<section vi-buffer></section>

Use the ngVideoOptions for modifying the necessary values pertaining to the vi-buffer directive: BUFFER_COLOUR, BUFFER_HEIGHT, BUFFER_WIDTH.

Note: ngVideoOptions can be injected into your controllers in the same way as services: see ngVideoOptions.

Example of two buffering segments from Safari with [email protected] โ€“ notice the two red lines:

ngVideo 0.2.2

Controls

The vi-controls directive allows you to add a play button and a pause button to your player โ€“ vi-controls-play and vi-controls-pause respectively, where vi-controls serves as the parent which contains the logic.

<section vi-controls>
    <a vi-controls-play>Play</a>
    <a vi-controls-pause>Pause</a>
</section>

Feedback

Provides information relating to the video itself โ€“ such as the duration, loading, et cetera... By adding the vi-feedback directive to a node, your node will inherit lots of useful properties for the end user.

<section vi-feedback>

    <ul>
        <li>Time: {{currentTime}}s / {{duration}}s</li>
        <li>Volume: {{volume}}</li>
        <li>Buffered: {{buffered}}%</li>
        <li>Loading: {{loading}}</li>
        <li>Playing: {{playing}}</li>
    </ul>

</section>

Currently the vi-feedback supports the following properties โ€“ as of [email protected]:

  • buffering;
  • currentTime;
  • duration;
  • volume;
  • buffered;
  • loading;
  • playing;
  • playbackRate;

Full Screen

With the vi-full-screen directive you can open the player into full-screen mode depending on browser support.

<a vi-full-screen-toggle>Toggle Full-Screen!</a>

With the vi-full-screen-toggle directive, ngVideo whether it should open or close the full screen mode. If you wish to force either the open and close, or have two different buttons for each action, then you can use vi-full-screen-open and vi-full-screen-close in place of vi-full-screen-toggle.

Meta

In some cases you may wish to read the meta data of a video without actually playing it. For example, you may wish to know the duration of a video for the playlist โ€“ just so the user knows!

Simply wrap the videoModel in the vi-meta directive and you will have access to the video's meta data:

<span vi-meta ng-model="video">
    {{duration}} seconds.
</span>

Messages

With the vi-messages directive you can subscribe to all of the native video events and filter them depending on whether they're informational or a more serious error.

<section vi-messages>

    <ul>
        <li ng-repeat="message in messages">
            
            Date: {{message.date}}
            Text: {{message.text}}
            Type: {{message.type}}
            
        </li>
            
    </ul>

</section>

Playback Rate

By adjusting the playback rate you can increase of decrease the speed of the video โ€“ you can achieve this with the vi-playback-rate directive which sets the playback rate in absolute terms. You also have vi-playback-rate-increment, vi-playback-rate-decrement and vi-playback-rate-normalise.

<section>
    <span vi-playback-rate="2">Double Speed</span>
    <span vi-playback-rate-increment="1">Increment by 1</span>
    <span vi-playback-rate-decrement="1">Decrement by 1</span>
    <span vi-playback-rate-normalise>Normalise</span>
</section>

Playlist

With the vi-playlist directive you can manage your list of videos โ€“ by applying the vi-playlist directive; it overrides the videos array. With your videoModel you should attach it to the directive using the ng-model attribute.

<section vi-playlist>

    <ul>
        <li vi-playlist-video ng-repeat="video in videos" ng-model="video">
            Play: {{video.src}}
        </li>   
    </ul>

</section>

As well as listing the videos in the current playlist, the vi-playlist contains useful methods for traversing the playlist:

  • next();
  • previous();
  • first();
  • last();

Note: You don't need to use the ng-model approach; vi-playlist has access to the open method which requires the passing in of the videoModel.

Seekable

Using the vi-seekable directive you can update the player's current time either absolutely or relative to the current time. For this ngVideo has three directives: vi-seekable, vi-seekable-increment, and vi-seekable-decrement.

Each of the three directive accepts a parameter which is used to either set the time in seconds absolutely โ€“ as in the case of vi-seekable, or relatively, in the case of both vi-seekable-increment and vi-seekable-decrement

<section>
    <span vi-seekable="20">20 Seconds</span>
    <span vi-seekable-decrement="10">Minus 10 Seconds</span>
    <span vi-seekable-increment="10">Plus 10 Seconds</span>
</section>

Screen

The vi-screen directive is the only mandatory directive โ€“ along with the core ng-video directive for managing the core logic. It is also one of the simplest directives, because it simply outputs the video node โ€“ with a little behaviour thrown in.

<video vi-screen></video>

Timeline

Keeping with the simplicity of the vi-screen directive, the vi-timeline is equally as simple, and contains the input โ€“ with type range for notifying the user of which position they're at in the current video/audio.

<input vi-timeline />

Volume

Directive has the ability of modifying the volume and bundles with four useful directives for common tasks: vi-volume-decrease for decreasing the volume, vi-volume-increase for increasing, vi-volume-loudest for the maximum volume, and the vi-volume-mute directive for muting the audio. However, the vi-volume directive has access to the setVolume method which allows you to specify the audio level.

<section vi-volume>

    <a vi-volume-decrease>Decrease</a>
    <a vi-volume-increase>Increase</a>
    <a vi-volume-mute>Mute</a>
    <a vi-volume-loudest>Loudest</a>

</section>

Note: For access to the volume property, it is necessary for the vi-volume directive to be a child of the vi-feedback directive.


Configuration

ngVideo uses ngVideoOptions for its configuration parameters โ€“ ngVideoOptions is injectable into a controller in the same way as a service is.

myApp.controller('VideoController', ['$scope', 'ngVideoOptions',

function($scope, ngVideoOptions) {

    // Change the colour of the buffer bar to blue.
    ngVideoOptions.BUFFER_COLOUR = '#00f';
    
}]);

You can inspect the ngVideoOptions object using your favourite debugger.

Below are a few of the parameters you may wish to play with:

  • REFRESH: Properties refresh interval in milliseconds โ€“ default being 50 milliseconds;
  • VOLUME_STEPS: Incremental and decremental steps of the volume โ€“ default 0.1;
  • VOLUME_MAXIMUM: Maximum volume that can be set โ€“ default is 1;
  • VOLUME_MINIMUM: Minimum volume that can be set โ€“ default is 0;
  • BUFFER_COLOUR: Colour of the canvas element in the vi-buffer directive;
  • BUFFER_HEIGHT: Height of the canvas node in the aforementioned directive;
  • BUFFER_WIDTH: Width of the canvas node in the aforementioned directive;
  • SCREEN_CHANGE: Whether clicking on video toggles video state;
  • TIMELINE_CHANGE: Whether changing range reflects in seeking;

Custom Build

As ng-video has a modular design, you can compile your own version of ng-video depending on the directives you wish to use.

For example if you want a simple player with the play and pause buttons, and a volume control, then including the entire ng-video module would be wasteful. Instead you could compile your own ng-video.custom.min.js using the following grunt command:

grunt custom --modules=Controls,Volume

Each of the modules are separated by a comma โ€“ and three essential modules are included no matter what: Service.js, Bootstrap.js, and Screen.js.

Once you've issued the grunt custom command your custom builds โ€“ development and minified, will be present in the dist/custom directory.


Contributing

Karma.js

ngVideo uses Jasmine with the Karma runner. All contributions to ngVideo are welcome!

Please add a unit-test for your addition โ€“ or removal, and then run all of the tests using karma start KarmaUnit.js, or with Grunt: grunt test.

Once you've committed your changes to your branch and all tests are passing, please open a pull request for review.

More Repositories

1

ReactShadow

๐Ÿ”ฐ Utilise Shadow DOM in React with all the benefits of style encapsulation.
JavaScript
1,303
star
2

Leaflet.FreeDraw

๐ŸŒ FreeDraw allows the free-hand drawing of shapes on your Leaflet.js map layer โ€“ providing an intuitive and familiar UX for creating geospatial boundaries similar to Zoopla and others. Included out-of-the-box is the concaving of polygons, polygon merging and simplifying, as well as the ability to add edges and modify existing shapes.
JavaScript
526
star
3

Maple.js

Maple.js is a React webcomponents based framework mixing ES6 with Custom Elements, HTML Imports and Shadow DOM. It has in-built support for SASS and JSX, including a Gulp task for vulcanizing your project.
JavaScript
431
star
4

Magento-on-Angular

Angular.js application using Magento as the backend API
PHP
361
star
5

Legofy

Legofy your images with retina support using SVG.
JavaScript
301
star
6

ngDroplet

Angular.js HTML5 file uploading with drag & drop and image/file preview.
JavaScript
287
star
7

Switzerland

๐Ÿ‡จ๐Ÿ‡ญSwitzerland takes a functional approach to Web Components by applying middleware to your components. Supports Redux, attribute mutations, CSS variables, React-esque setState/state, etcโ€ฆ out-of-the-box, along with Shadow DOM for style encapsulation and Custom Elements for interoperability.
TypeScript
268
star
8

Keo

Plain functions for a more functional Deku approach to creating stateless React components, with functional goodies such as compose, memoize, etc... for free.
JavaScript
227
star
9

Standalone

Create framework agnostic components that are truly reusable and interoperable with all the benefits of the React ecosystem โ€“ using the HTML5 custom elements API to extend HTML's vocabulary.
JavaScript
206
star
10

Snapshot.js

Node.js app for slicing and dicing ~100,000 models in <5ms with easy sorting, paginating, and filtering.
JavaScript
202
star
11

EmberDroplet

Ember.js HTML5 file uploading with drag & drop and image/file preview.
JavaScript
198
star
12

EmberSockets

Socket.io (WebSockets) integrated with Ember.js' observer pattern.
JavaScript
136
star
13

Dory

Dory is a responsive, universal, GitHub collaborated blogging platform built on React and powered by Express. By combining awesome features such as automatic RSS generation, HTML5 offline support, push notifications, with a powerful development environment using hot reloading, SASS and Markdown, Dory allows developers to quickly dive into the depths of blogging.
JavaScript
128
star
14

Interpose

Apply stylesheet variables to your React components for use in your stylesheets. Interpose reduces the clutter of React components by bridging the gap between JS and CSS without resorting to complicating your components with CSS logic.
JavaScript
126
star
15

Mocktail

๐Ÿน Mock all of your ES6 module components with Mocktail using dependency injection.
JavaScript
103
star
16

ngCrossfilter

Usual Angular.js style filtering and sorting with a twist of Crossfilter for improved performance.
JavaScript
87
star
17

ngContextMenu

Handcraft your very own context menus for a richer UX!
JavaScript
80
star
18

gulp-processhtml

Process html files at build time to modify them depending on the release environment
JavaScript
77
star
19

L.Pather

Branching from Leaflet.FreeDraw, L.Pather is a freehand polyline creator that simplifies the polyline for mutability.
JavaScript
69
star
20

Freelancer

๐Ÿ‘” An implementation of on-the-fly defined WebWorkers that are created inline using data URIs, rather than separate physical files โ€” for the benefit of all humanity.
JavaScript
67
star
21

Amelie

HTML5 audio visualiser experiment using D3 with a curious Amelie theme.
JavaScript
57
star
22

ngRangeSlider

Multi-handle range slider utilising the native HTML5 input range elements.
JavaScript
54
star
23

EmberCrossfilter

Instead of using Ember DataStore, EmberCrossfilter provides a basic architecture for creating Ember models with Crossfilter; which allows for much quicker sorting and filtering.
JavaScript
48
star
24

DetectFont

Detect which font your system has cherry-picked from font-family.
JavaScript
41
star
25

CloudConvert

Easy-to-use Node.js implementation of the CloudConvert API.
JavaScript
38
star
26

Redecorate

Simple module for reducing immutable nested properties in Redux applications.
JavaScript
27
star
27

ngPourOver

PourOver wrapper for Angular.js with super-quick filtering and sorting.
JavaScript
27
star
28

ReactDelayed

Small component for delaying the mounting and unmounting of a child component for CSS animation purposes.
JavaScript
21
star
29

ngImgur

Take your favourite cat picture, and upload it to Imgur.com w/ Angular!
JavaScript
17
star
30

RedisCache

Simple Node.js based Redis cache for storing large collections of data.
JavaScript
16
star
31

ngRoundabout

Three-dimensional HTML5 carousel implemented in Angular.js.
JavaScript
14
star
32

ReactCrossfilter

Crossfilter.js implemented as a mixin for ultra-fast filtering and sorting techniques baked into React.js components.
JavaScript
13
star
33

ngDonut

Lightweight and extensible Angular implementation of the D3 donut graph.
JavaScript
11
star
34

Readlint

๐Ÿ“™Lint all of the code examples in your README documentation using shared configs.
JavaScript
10
star
35

ngObelisk

Easily use Obelisk to create animations using Angular.js.
JavaScript
10
star
36

ngTeleport

Move a section of the DOM and inherit the scope of the target node.
JavaScript
9
star
37

Webmonkey

๐Ÿ™Š Robust and versatile headless monkey testing for the modern web with reproducible steps, error alerts, strategy sharing and many other good things.
JavaScript
9
star
38

Formv

๐Ÿ—ณReact form validation using the validation native to all recent browsers. Also includes support for handling API validation messages, success messages, memoized and nested form state, and super easy styling.
JavaScript
9
star
39

Taskfile

๐Ÿ“ฆ Yet another attempt at a simple task runner for npm with parallelisation support using bash commands via YAML.
JavaScript
8
star
40

EarthApp

Three.js w/ Angular implementation of planet earth using SketchUp for the models.
JavaScript
7
star
41

EmberRickshaw

Rickshaw faรงade for Ember which allows automatic redrawing of graphs using Ember's observer pattern.
JavaScript
7
star
42

Memoria

Extensible form storage for memorising user inputs with local storage. Never lose your form data ever again!
JavaScript
7
star
43

Koi

Koi is a time aware interactive bird written in THREE.js with voice recognition, and an artificial IQ.
JavaScript
6
star
44

Pellucid

Experimental module using HTML5's Custom Elements that creates a crystalline blurred background.
JavaScript
6
star
45

Catwalk

Intuitive and fast relational CRUD interface for modelling relationships using vanilla objects written in ES6.
JavaScript
6
star
46

Mapleify

Mapleify is a build tool for Maple.js; it uses Polymer's vulcanize to process HTML imports with a little twist of Maple specific logic for HTML Import paths, and the processing of SASS/JSX documents.
JavaScript
6
star
47

Bi-cycle

Bi-cycle assists in making infinite carousels and sliders by handling the index logic for you.
JavaScript
5
star
48

Openroulette

Openroulette is a Chatroulette implementation built using the WebRTC component.
JavaScript
4
star
49

Vik

CLI Semver autoincrement with major, minor, and patch.
JavaScript
4
star
50

Draught

Drawing tool in ES6 for creating diagrams using D3 with an extensible event driven architecture.
JavaScript
4
star
51

Maducer

An experimental map-reduce concurrency over web workers using shared array buffer for handling large datasets.
JavaScript
3
star
52

OrderlyQueue

Implementation of a promise-based FIFO queuing system using ES2017 async generators.
JavaScript
3
star
53

AnsibleAlexa

Development deployment using Vagrant w/ Ansible provisioner.
PHP
3
star
54

Canvas-Background

A super useful function for applying a background colour to a canvas element before invoking toDataURL.
JavaScript
3
star
55

MayBee

Safe chaining of object properties and functions using ES2015 Proxy.
JavaScript
3
star
56

Angularise

Deferred compilation of Angular.js templates for applications that render HTML from asynchronous processes.
JavaScript
3
star
57

PointerEvents

Allow the emulation of pointer events for browsers without native support, such as Internet Explorer.
JavaScript
3
star
58

Instamap

โœˆ๏ธ Towards the end of 2016, Instagram removed the Photo Maps feature. Instagram says it was unused, but we remember! Instamap brings it back for good, open-source and ad-free.
JavaScript
3
star
59

mundus-meus

Leaflet.js & Angular.js mapping tool for finding entities based on your location.
JavaScript
2
star
60

Typified

๐Ÿ—ผAn experimental implementation of first class functional types using pure ES at runtime, inspired by Haskell, PureScript and Idris.
JavaScript
2
star
61

Banter.js

Angular based real-time app for communicating with customers via IRC. Individual customers connect to a common IRC channel, giving staff members the ability to see all customers' messages, with the ability to respond directly and individually.
JavaScript
2
star
62

UMLApp

JavaScript
2
star
63

Needle.js

Angular.js style dependency injection using reflection.
JavaScript
2
star
64

Biutiful

๐ŸŒฟ Biutiful transform ES imports into browser usable ECMAScript imports.
JavaScript
2
star
65

Shift.js

Use the shift key to select a range of elements, such as checkboxes.
JavaScript
2
star
66

Lenin

Diagram tool using D3 providing a set of common functions for easy integration and extensibility.
JavaScript
2
star
67

UploadButton

UploadButton is a tiny module for a custom stylable upload button. Using HTML5's Custom Element API and Shadow DOM for encapsulation.
JavaScript
2
star
68

Tail.cat

Modern e-mail client and SMTP/POP server using MongoDB, Ruby, Angular
JavaScript
2
star
69

Tessellate

Small vanilla JavaScript module for gracefully removing floating elements from the page.
JavaScript
2
star
70

PolymerDroplet

Polymer.js adaptation of my popular EmberDroplet module for Ember.js.
JavaScript
2
star
71

DjangoExceptions

Handle and parse Django REST Framework validation messages with aplomb.
JavaScript
2
star
72

Moggy

Miniature ~2kb library that brings immutability to existing prototype functions employing the principle of least astonishment.
JavaScript
2
star
73

NodeURLImports

Transform browser URL imports into Node compatible import/require statements using local dependencies.
JavaScript
2
star
74

Viewport

Determine how much of an element is visible in the viewport.
JavaScript
1
star
75

ReduxLocal

Redux helper for maintaining pseudo-local state in a single tree.
JavaScript
1
star
76

Tdo

Terminal based todo app for managing today's tasks with gentle reminders
Rust
1
star
77

Tidal.js

Socket.io benchmarking with realtime web-based statistics.
JavaScript
1
star
78

Memor

Use memoization for Rust functions to increase performance
Rust
1
star
79

Kiwi.js

DRY interface for Angular.js tests in Jasmine/Karma.
JavaScript
1
star
80

Workex

1
star
81

Funkel

Simple and lightweight functional toolset inspired by Clojure using import.
JavaScript
1
star
82

StickyRice

๐Ÿš React implementation to allow the natural position sticky behaviour in table headers and other elements
JavaScript
1
star
83

Hylian

Quick and easy doubly and singly linked immutable list implementation that allows for inserting, removing and shifting.
JavaScript
1
star
84

DeveloperInk

Facilitates the use of ZURB's Ink for developers using the CLI with SASS, Email Testing, Compilation, etc... ๐Ÿ™
CSS
1
star
85

WeakTree

๐ŸŒฒWeakMap implementation that allows for composite keys in a tree formation.
JavaScript
1
star
86

Mareos

MapReduce over WebSockets using Goroutines.
Go
1
star
87

SetOrder

Tiny module for sorting by a set order, using a custom sort function for omitting explicits.
JavaScript
1
star
88

Paramo

๐ŸŒตSwiss-army knife of stringifying, parsing and manipulating URL parameters by applying types to the parameters.
JavaScript
1
star
89

ava-webcomponents

Utility middleware for testing web components in AVA via Puppeteer.
JavaScript
1
star
90

Regrowth

๐Ÿ”ฌRegrowth is a monstrous laboratory experiment in container queries brought to life.
JavaScript
1
star
91

Cinematic.js

Experimental module for video sequence scrolling with zero dependencies.
JavaScript
1
star
92

Termtodo

Todo app for the terminal for keeping reminders for later
Rust
1
star
93

Honey.js

Simple JavaScript library with auto-updating templates.
JavaScript
1
star
94

ReactAutolist

Browser native implementation of autocomplete using the datalist element.
JavaScript
1
star
95

Relayed

Convenient Node.js app for circumventing CORS issues when developing on localhost.
JavaScript
1
star
96

Doogle

Node.js app for taking HTML snapshots of JavaScript pages to make your dynamic apps Google crawlable.
JavaScript
1
star
97

gulp-envy

Gulp plugin for transferring your chosen environment variables to objects, with module loader, globals, angular, and other strategies.
1
star
98

redux-nest

Redux middleware for wrapping store in a Proxy to help with complex nested states.
JavaScript
1
star
99

Async

Yet another simple Promises/A+ compliant async flow control using ES6 generators.
JavaScript
1
star
100

TravelMap

๐ŸŒ Pin visited locations on a simple-to-use map, as well as future places you'd love to see. Then share with the world!
Python
1
star