Using WebButton to control YouTube playback

I want to have a WebButton on a WebPage that pauses the playback of a Youtube video loaded in a WebHTMLViewer. I don’t want to use the Youtube controls to control playback.

The Youtube video is loaded using the WebhHTMLViewer LoadPage method (where vid is the youtube id):

  me.LoadPage("<iframe id='yt' src='"+vid+"?enablejsapi=1'></iframe></div>") 

When I run it, the Youtube video plays, but when the button is pressed I get an error message indicating the object with id ‘yt’ is null. Here’s the line in the WebButton Action event:


Thanks in advance for your help.

A WebHTMLViewer control creates an iframe on your page, so your iframe is inside of that one. You’ll need to chain down through the WebHTMLViewer’s iframe by using it’s ControlID. Or better yet, don’t create your own iframe, just assign the URL of the WebHTMLViewer to the youtube url.

If Xojo is creating the iframe, what is the id? The ControlID?

So, something like this should work?


And code in WebHTMLViewer1 is:

me.url =“"+vid+"?enablejsapi=1’>”

I’ll try it tomorrow if you think that will work.

I didn’t realize WebHTMLViewer control created iframe. Thanks for that info.

Damn. I meant:

me.url =“"+vid+"?enablejsapi=1

I’ve done all the work for using the YouTube Javascript API in Studio Stable Web Essentials. Info on the control is here:

A demo is here. Click the “#2? segment at top left, then the “YouTube” segment at top right.

A license (EDIT: includes full Xojo source) will set you back $69.95. If you value your time and sanity at $5/hour, you’ll break even on this control.

Hello Brad, All,

Are you still offering your YouTube API examples and resources?

I am trying to build a new web site on Xojo Clou, to play YouTube clips, with the clip code launched from my web app, but for the stream to go straight to YouTube so it does not use anything from the allotted 2 TB (or 4 TB) limit of transfer data/month (per Xojo Cloud).

The main things I need to get in my Xojo Web App are (a) to know if the clip is running (at all), and (b) how many seconds it has played. The least JavaScript codes to use the better.

-Simon @ Nashville, TN