Coder Social home page Coder Social logo

ngvideo's Introduction

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.

ngvideo's People

Contributors

statukuo avatar stewarthaines avatar wildhoney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngvideo's Issues

files ng-video

where the files are ng-video/Controls.js and ng-video/FullScreen.js ???

Player loop

Hello, I don't understand how to use this feature :

if ($scope.player.loop) { // Determine if we should keep looping the playlist. playByIndex(0); return; }

I would like to go back to the first video after the last one is finish but I don't understand how I can do that. I I put "loop" on the screen directive, it will loop only on the first video and the index never change..

Thanks for your help.

Endless video playlist.

Hello.
I have 5 videos. And I want to play this playlist forever. The 1st video will start automatically after the 5th video. How can it be implemented? Thank you.

Video list needs an empty function

Hi,
The video object is an angular service which means that there is only 1 instance of the object and it survives for the duration of my page.
Every time I navigate to a page to play a video and use addSource to add a video the video is added to the top of ngVideoPlaylist array and the array keeps getting bigger.

I have added the following to the video object
service.resetSource = function clearSource(){
// clear the array of items to play
ngVideoPlaylist.length = 0;
}
This allows me to reset the list when I need to.

Play/pause toggle

How would you go about setting up a control that toggles between play and pause rather than two separate controls on screen?

Multiple videos within ng-repeat

Hi everybody,

I'm trying to output different videos based on a json file I iterate through ngRepeat. All seems to work fine but the video source is the same for all the videos even if I encapsulated the section in a inner controller in order to manipulate the model accordingly to my needs. The other elements in each section work just fine but the video doesn't. Is there anything I missed? Any ideas?

Thanks!

Alive?

Is this project still alive?

The example has some problems:
The vendor files for bootstrap, angularjs and common.js are missing.

I don't want to utilize a dead project.

Thanks!

Using ngVideo in Cordova

Hi,
I can't see any issues at the moment but it would be usefull if you could provide an initalise function that I can call rather than just initalise as the code is loaded.
When using Cordova the page is ready only when the Cordova framework fires the "deviceready" event. At this point I can call any special initalisation functions, for angular I call angular.bootstrap rather than relying on the ngApp to auto bootstrap.
See the cordova documentation here
http://cordova.apache.org/docs/en/4.0.0/cordova_events_events.md.html#deviceready

Video update on location change

I need to play a video depending on the URL. Like if it changes from .../video/1 to .../video/2, the player should play the video 2 instead of video one, in the controller, I update everything based on the $routeParams value, the view is changed, everything else works fine EXCEPT the video, it just doesn't load. Any ideas?

Feedback not updating using vi-timeline when video is paused.

So, there is this stupid error. When I pause the video and use the vi-timeline directive to change the currentTime of the video, the content of the video is updated i.e the video is seeked to the new position BUT the values in the vi-feedback never change(the currentTime watch yields no result, and the labels dont show updated values either.

Unknown provider on injecting "video" in controller.

Error: [$injector:unpr] Unknown provider: videoProvider

.controller("myCtrl",["$scope","$sce","$ionicLoading","$filter","video",function($scope,$sce,$ionicLoading,$filter,video){

}

here i am getting error on injecting video

vi-playlist-video

First of all, I want to say thank you for this awesome module. It's 98% what I need, so I'm very thankful.

I have it working great with a series of videos I set in my item controller and which the player plays through with no problem. But when I go to "render" the playlist under the player using exactly the code listed [here:https://github.com/Wildhoney/ngVideo#playlist], the playlist renders fine, but I get this error in my console: http://errors.angularjs.org/1.2.20/$injector/unpr?p0=aProvider%20%3C-%20a%20%3C-%20viPlaylistVideoDirective and clicking the items has no effect on the player.

What am I doing wrong?

Thank you,
~Todd

setVolume on initialization

Hi there!

In my particular case I need to start the video muted. Haven't found anything on docs about it.

How can I setVolume(x) on initialization? I mean, I can use the controller to grab the apropriate scope where the interface is, but... shouldn't we be able to access directly the controls from the controller?

Thanks in advance

Playback rate = 1/fps possible? Callback for each frame?

I'm using a playback rate of say 0.033 which is 1/30 so that I can view the video frame by frame. Now I have two problems:

  1. I'm not sure its actually playing it at that rate.
  2. Is there any way I can extend the directive to get a callback every time the frame is changed? I need to do some drawing based on the frame number.

Full Screen doesn't work correctly

Hi,
When entering full screen mode the browser goes full screen but the video doesn't change size.
I believe that this is because full screen is called on the container e.g.
scope.container.requestFullscreen
rather than the player e.g.
scope.player.requestFullscreen

When I change the code to use player rather than container the video plays full screen

bower install does not include CSS/imagery needed to render videos as shown in README

After installing via bower, I followed the basic instructions to get a video up, adding a controls section for play and pause. Thankfully, my video rendered, but Play and Pause controls only appeared as text under the video, to the left. Not seeing any CSS in the dist folder, I grabbed the default.css from the example provided in this repo and got a little farther (shadowed box around video, video size scaling as browser scales), but the Play and Pause texts still appear:

ngvideo txtctrls

I prefer to see them appear as icons, the way they appear in your README, for example:

https://camo.githubusercontent.com/bd8fa4b0847131a53cad59221c29b2683e4d763c/687474703a2f2f692e696d6775722e636f6d2f506f46386a37302e706e67

video is playing in loop

i am using this plugin and one thing i observed is that it's playing in loop ,once the video ends ,it starts again and again ,is there any config i am missing or its a bug

Data binding source?

Hi,

Is there a ready-made way to use data-binding and not work through the video service in my controller?

I am looking for a way to do something like this:

<div ng-repeat="post in timelinePosts">
    <div class="video-container">
        <section class="video" ng-video video-source="someControllerPropertyOrMethod">
            <video vi-screen></video>
        </section>
    <div>
<div>

I guess this whole thing (the inner div) could be encapsulated in a directive but I was wondering if there is a ready made one or an example of how to accomplish that (I'm js/angular noob).

Thanks,

Tomer

Controls broken in Firefox

Firefox has a slightly different implementation of HTML5 video that does not play nicely with this directive. Specifically, Firefox implemented clicking the video to play/pause internally, where the other browsers don't do this. The result is that the directive tries to do the same thing, and the events essentially cancel out. This prevents the play/pause button from working.

I have worked around this locally by detecting the browser in the click event on the video and not calling toggle if it is Firefox. This will work until Firefox changes their implementation. Not sure if there would be any way to detect the implementation and act accordingly so we aren't having to check if the browser is Firefox.

poster image or check if video valid?

Hi there!

I'm getting a little dificulty understanding how to check if the video feed is valid.... should I do it before giving a src to ngVideo or is there some feature already in place?

ngVideo is based on http://www.html5rocks.com/en/tutorials/video/basics/ right? How can I assign a poster image? docs say nothing about it...

Should we do it on the screen directive?

<!-- Screen Directive --> <video vi-screen loop muted autoplay preload="auto" poster="{{item.bgImg}}"></video>

Thanks

vi-timeline is not moving while the video is playing

So i have this problem, I'm using vi-timeline directive to see where I'm currently at in the video, but as the video is playing, the slider doesn't move an inch.

If i click on it and slide it right and left, the video does go back and forth but again while the video is playing, the slider doesn't move.

Is there something I'm missing?

Thank you.

Where can I find a example with all the features

Can you help me to have some example with all features (full-screen,controls)?
In the example with the source, only play and stop work others features can't find any sample.
Thanks in advance for your help.

Playback rate with autoplay

Adding vi-playback-rate you're able to set the playback rate, but it only apply when you Play the video.

If the video is set to autoplay, you got to pause and play to apply. Is there a way that it can be applied before the video starts?

Backbutton

Hello! I'm trying to pause the current playing video (if there is any) when the user tap the back button. But I don't have any clue how to pause it from other context, I think that #15 refers to similar issue.

I was wondering with something like:

  $scope.$on('backbutton', function(){
    // Pause?
  });

I've checked that exist a player object, but, is a grand grand child scope of the current control. Somebody can give a hand with this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.