How to add tap event to youtube iFrame

2019-01-20 18:56发布

问题:

Having an youtube iFrame, I got very limited control over it in Sencha touch.

So here is my code where I add and initialize youtube iframe:

        this.player = {
            xtype: 'panel',
            id: "youtubeVideo",
            styleHtmlContent : true,
            html: '<iframe id="player" type="text/html" width="320" height="240" src="http://www.youtube.com/embed/' + youtubeid + '?enablejsapi=1" frameborder="0"></iframe>',
            listeners:{
                tap:{
                    element:'element',
                    fn: function () {
                        alert('hey')
                        console.log("I want to proceed with some events in here!!!")
                    }
                }
            }
        }
        this.add([this.player])

And as you can see that I tried to attach tap function to panel, which basically should enable some custom logic.

Could you please let me know what is the solution for listening to the iframe tap?

回答1:

The way I have done it is to grab the thumbnails from the YouTube .json feed and format that into a dataview.....the the tap listeners become easy. Have a look at the o'reilly example if you want to see how YouTube .json is called.

You could listen for a tap on the panel, using that I'd you specified, does that work?

:-)