Reputation: 171
I wrote an AngularJS directive for vimeo videos with built in play/pause functionality using their froogaloop library.
It's works great! The only issue is that I get the following error when the page first loads.
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://player.vimeo.com') does not match the recipient window's origin
Am I initializing the froogaloop object wrong in the directive? Any suggestions would be most appreciated.
You can check it out the plunker here: http://plnkr.co/edit/GKWNk3LhX0MR3lhpfqyA
Upvotes: 16
Views: 10504
Reputation: 1800
I recommend to execute the code in the onLoad
event from <iframe>
. Then you are ensured that the code will execute when iframe is ready for receiving messages.
There are plenty ways to do it:
$('iframe').load(callback)
or iframe_element.addEventListener('load', callback)
or iframe_element.onload = callback
. Where callback
is the method which uses Froogaloop.
But you have to know that some of those solutions might have some drawbacks on some old/MS browsers browsers.
Upvotes: 6
Reputation: 1769
For me it looks like angularjs triggers Player API before actually rendering the iframe on the page. At least if I postpone scope.$watch it works fine:
$timeout(function() {
scope.$watch('controlBoolean', function() {/* your code goes here */});
});
Upvotes: 2