How to dynamically test if YouTube iframe API loads without onYouTubeIframeAPIready

I have a directive in AngularJS that plays (etc.) a YouTube video via the YouTube IframeAPI.

In the body of the directive, I will check if the IframeAPI is ready for

var playerReady = $q.defer();
window.onYouTubeIframeAPIReady = function() {
  console.log('YouTube API is ready.')
  playerReady.resolve();
}

      

This is done only once.

Then I have

return {restrict: 'E',
   link: function(scope, element, attrs) {

      

and so on, where I am looking at the scope variable, but that is not important here.

Then when my youtube element is done I can in the link init function if with playerReady.promise.then (...

)

It's inside the callback scope.$watch

.

This works well if my element is youtube

present in the first route, although if the video is only later set (I have ng-show=..."

to hide it until a certain event is triggered in the scope, and the linker function is watching this object in the scope), but if it goes to it later (i.e. the first route doesn't have my youtube element), I can't resolve playerReady anymore.

To summarize, how can I dynamically test later, what if the youtube iframe api is ready and therefore resolve mine playerReady

? I could do this in my supervisor.

This in the directive body solves the problem

setTimeout(function(){
  playerReady.resolve();
},3000);

      

but that's not how it should be done.

+3
angularjs youtube


source to share


No one has answered this question yet

Check out similar questions:

2263
How to get YouTube video thumbnail using YouTube API?
206
How to embed autoplaying YouTube video in an iframe?
thirty
Youtube iframe api does not start onYouTubeIframeAPIReady
3
how to get direct link from youtube video from youtube api v3
1
Youtube Javascript API (Chromeless player) won't play some videos?
1
How to hide new title bar in YouTube?
1
Ionic app not displaying YouTube videos in iframe on iOS device
1
YouTube api, Chrome extensions, YouTube developer key and 403 forbidden quotas
0
IOException while uploading YouTube video via Java API
0
How to parse xml without using youtube api



All Articles
Loading...
X
Show
Funny
Dev
Pics