Code Monkey home page Code Monkey logo

Comments (4)

brandly avatar brandly commented on June 14, 2024

:( this is true.

do you have any suggestions of how this should look? since there's only a single $youtube service for your entire app, instead of a single $youtube.player reference, it could be like $youtube.getPlayer(id), where id is the DOM id. that way, you can control multiple players.

for events, listeners could be passed something telling them the DOM id of the player, so you can distinguish like which one just paused or whatever it may be.

let me know if you've got advice.

from angular-youtube-embed.

oleyb avatar oleyb commented on June 14, 2024

I hacked together a messy solution to make it work for my basic use case, but reading your comment I realized theres probably issues related to the onPlayerStateChange event.

I'm just getting familiar with Angular directives so this probably isn't the ideal implementation but what I did was take everything that was in the service and move it into the link function of the directive. That way each instance of the directive had it's own youtube object to control. To make stuff work I also had to change $window.onYouTubeIframeAPIReady to use a global flag rather than a per instance boolean ready and look for that flag in stopWatchingReady.

I hope this helps! If I was more comfortable working with directives I'd fork and fix it for you, but I don't want to muck things up. :)

from angular-youtube-embed.

CWSpear avatar CWSpear commented on June 14, 2024

I'd have to dig closer into the code, but it by far makes the most sense to me to pass the player in from the events:

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

and/or you could expose the player to the directive:

<youtube-video id="best-vid" video-url="theBestVideo" player="bestVideoPlayer"></youtube-video>
// $scope.bestVideoPlayer may not be available right away. This is not something that
// should be done in a controller callback, but maybe in an ng-click, etc.
$scope.playVideo = function () {
  if ($scope.bestVideoPlayer) 
    $scope.bestVideoPlayer.playVideo();
};

I feel like you shouldn't have to expose the $youtube service at all.

from angular-youtube-embed.

brandly avatar brandly commented on June 14, 2024

fixed with b0c0083

from angular-youtube-embed.

Related Issues (20)

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.