Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48984

How to read embed youtube iframe events

$
0
0

Hi can anyone help with this problem. The youtube -plugin can’t do this. I assume this would be meaningful for many developers. So there is code that works well when writing/controlling youtube iframe:

HTML:

< "div id=“whateverID” style=“position:relative;padding-bottom:56.25%;padding-top:30px;height:0;overflow:hidden;”>
< iframe allowfullscreen=“1” frameborder=“0” title=“YouTube video player” allow=“autoplay” wmode=“transparent” style=“position: absolute;top: 0;left: 0;width: 100%;height: 100%;” >
< /div>

TS:

callInitPlayer(func, args) {
let i = 0,
iframes = document.getElementsByTagName(‘iframe’),
src = ‘’;
iframes[i].setAttribute(“src”,this.url);
// console.log('iframes: ',iframes,'func: ',func, 'args: ',args);
for (i = 0; i < iframes.length; i += 1) {
src = iframes[i].getAttribute(‘src’);
// console.log('src: ',src);
if (src && src.indexOf(‘youtube.com/embed’) !== -1) {
iframes[i].contentWindow.postMessage(JSON.stringify({
‘event’: ‘command’,
‘func’: func,
‘args’: args ||
}), ‘*’);
}
}
}

For example playing video from point 30s:
this.url = https://youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1&autoplay=1&playsinline=1;
this.callInitPlayer(‘seekTo’,[30,true]);

There are some documents about this:

I have not been able to make readings like getCurrentTime() work. jQuery gurus please help!

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 48984

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>