Code Monkey home page Code Monkey logo

angular-youtube-embed's Introduction

Angular YouTube Embed

Embed a YouTube player with a simple directive.

$ bower install --save angular-youtube-mb

Can I use it?

Sure! Let me show you.

<!-- Include the file -->
<script src="angular-youtube-embed.js"></script>
// Create your app with 'youtube-embed' dependency
var myApp = angular.module('myApp', ['youtube-embed']);
// Inside your controller...
myApp.controller('MyCtrl', function ($scope) {
  // have a video id
  $scope.theBestVideo = 'sMKoNBRZM1M';
});
<!-- Use 'youtube-video' as an element or attribute. -->
<!-- Must have an ID -->
<youtube-video id="best-vid" video-id="theBestVideo"></youtube-video>

It's that simple. See it in action.

But I only have a URL.

No problem.

$scope.theBestVideo = 'https://www.youtube.com/watch?v=sMKoNBRZM1M';
<youtube-video id="best-vid" video-url="theBestVideo"></youtube-video>

Is that it?

Not quite!

Events and Player Controls

  • youtube.player.ready
  • youtube.player.ended
  • youtube.player.playing
  • youtube.player.paused
  • youtube.player.buffering
  • youtube.player.queued

Events allow you to keep an eye on the state of things from your controller. For example, let's say you want to automatically play the best video.

// Inject '$youtube' dependency
myApp.controller('MyCtrl', function ($scope, $youtube) {
  $scope.theBestVideo = 'sMKoNBRZM1M';

  $scope.$on('youtube.player.ready', function () {
    $youtube.player.playVideo();
  });
});

A full list of $youtube.player methods can be found here.

Utilities

  • $youtube.getIdFromURL
  • $youtube.getTimeFromURL

For example, you could start your video at the URL-specified time.

$scope.$on('youtube.player.ready', function () {
    var time = $youtube.getTimeFromURL($scope.videoURL);
    $youtube.player.seekTo(time, true);
    $youtube.player.playVideo();
});

Player Parameters

YouTube's embedded player can take a number of optional parameters. You can find a full list here.

For example, you could hide the player's controls. Add player-vars to your embedded player.

<youtube-video id="best-vid" video-id="theBestVideo" player-vars="playerVars"></youtube-video>

And define playerVars in your controller.

$scope.playerVars = {
    controls: 0
};

Tests

I should write more of them.

$ npm install
$ npm test

angular-youtube-embed's People

Contributors

brandly avatar konradhalas avatar

Watchers

 avatar  avatar

Forkers

sandybemonkey

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.