From d2becba74f7874d5683f0fb1baf4ad8169f14868 Mon Sep 17 00:00:00 2001 From: Asier Iturralde Sarasola Date: Wed, 8 Oct 2014 19:04:42 +0200 Subject: [PATCH] Youtube's play button didn't work in hybrid apps created using cordova --- src/angular-youtube-embed.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/angular-youtube-embed.js b/src/angular-youtube-embed.js index eb637b3..94c4486 100644 --- a/src/angular-youtube-embed.js +++ b/src/angular-youtube-embed.js @@ -166,6 +166,28 @@ angular.module('youtube-embed', ['ng']) } function onPlayerReady (event) { + + // Youtube's play button didn't work in hybrid apps created using cordova. + // This is a workaround based on this question from stackoverflow: + // http://stackoverflow.com/questions/26155372/youtube-iframe-phonegap-touching-tapping-the-red-play-button-the-video-doesn/ + var iframes = document.getElementsByTagName('iframe'); + var content; + var buttons; + + for (var i = 0; i < iframes.length; i++) { + + content = iframes[i].contentDocument; + buttons = content && content.getElementsByClassName('ytp-large-play-button'); + + if (buttons) { + for (var j = 0; j < buttons.length; j++) { + + buttons[j].addEventListener('click', function() { scope.player.playVideo(); }, false); + + } + } + } + applyBroadcast(eventPrefix + 'ready', scope.player, event); }