4

I'm trying to load a YouTube video into a TWebBrowser in Delphi XE7 and I'm getting an error that says this:

Adobe Flash Player or an HTML5 supported browser is required for video playback.
Get the latest Flash Player
Learn more about upgrading to an HTML5 browser

I can load normal HTML just fine.

The examples I've found posted here earlier are for much older versions of Delphi, so I'm wondering if this is an issue with newer versions, or TWebBrowser, or something in my environment (VMWare 7 with Windows 7).

EDIT: My objective is simply to be able to load and play a video from a URL, like a YouTube video. Solutions other than TWebBrowser are fine, especially if they can run cross-platform.

David Schwartz
  • 1,756
  • 13
  • 18
  • Which version of IE is running in the control? Did you set the registry keys and doctype to ensure that you get modern IE. – David Heffernan Jun 01 '15 at 06:19
  • Don't know, no, and no. Just used the example code in the earlier post from 2010. – David Schwartz Jun 01 '15 at 06:23
  • BTW, IE works fine. It's IE 11. – David Schwartz Jun 01 '15 at 06:25
  • You are probably using IE6 in some compat mode then!! Read this: http://stackoverflow.com/questions/25843845/how-to-have-delphi-twebbrowser-component-running-in-ie9-mode/25843958#25843958 – David Heffernan Jun 01 '15 at 06:25
  • I'd rather not require any setting changes to the registry. The only thing in that list is AcroRead.exe. Not clear what DOCTYPE needs to be in the HTML stream for this. Any ideas? ** !DOCTYPE html public "-//W3C//DTD HTML 4.0//en" ** isn't working. – David Schwartz Jun 01 '15 at 06:32
  • You need to extract the real URL of the video and then you can try this. WebBrowser1.Navigate('about:blank'); Doc := WebBrowser1.Document; Doc.Clear; Doc.Write(''); Doc.Close; If you want to go this way I have a calcc which can extract the real URL of a youtube video. – Jens Borrisholt Jun 01 '15 at 06:36
  • what would be an example of the real url of the video? Different from the ones in the share links? – David Schwartz Jun 01 '15 at 06:39
  • Have a look at this question http://stackoverflow.com/questions/29466625/screenshot-of-webbrowser – Jens Borrisholt Jun 01 '15 at 06:42
  • Else you can just play the video you self with Mediaplayer. – Jens Borrisholt Jun 01 '15 at 06:45
  • @David It's all explained in the link I gave you. I tried to say more in my answer. Not wishing to modify registry is rather unhelpful for you. That's the mechanism that MS offer. Take it or leave it. There is no other way. – David Heffernan Jun 01 '15 at 06:53
  • 1
    @DavidSchwartz: By default, the embedded browser runs in IE6 mode, even if you have IE11 installed. If you do not want to change registry keys, then the only way you can get out of this problem is to modify the webpage (add tag `` ) – whosrdaddy Jun 01 '15 at 06:56
  • @DavidSchwartz you don't. I'll say you should play the video you self on a TPanel. If interested I can make you an complete example. – Jens Borrisholt Jun 01 '15 at 06:58
  • 1
    Hey blame [microsoft](https://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx?f=255&MSPPError=-2147217396#browser_emulation), not us? And you can write the key to HKCU from your app, so it really is not a problem? – whosrdaddy Jun 01 '15 at 06:59
  • Exactly. It's you code. Just slap the setting into HKCU and move on. Trying to play you tube videos on IE6 in 2015 is not going to work out. – David Heffernan Jun 01 '15 at 07:02
  • @DavidSchwartz I can make you an example where you embed the video in you application not using TwebBrowser. If interested. But I won't spent time on it unless you want to use it – Jens Borrisholt Jun 01 '15 at 07:04
  • 1
    @JensBorrisholt yes I'd love to see an example. Thank you. – David Schwartz Jun 01 '15 at 07:10
  • I'm using the post http://stackoverflow.com/questions/3931487/is-there-any-other-way-to-view-youtube-video-on-delphi as an example, and it's not working in XE7. I'd love to see an example that DOES work in XE7 that does not require having users edit their registry (or the app doing it itself, b/c that tends to trigger anti-virus software). – David Schwartz Jun 01 '15 at 07:12
  • That post is from 2010. Perhaps you need a time machine. Hard to see that as a better solution than a reg setting in HKCU. – David Heffernan Jun 01 '15 at 07:18
  • 1
    For the love of god, it's not a delphi component, it's a system component!! http://www.google.com/search?q=delphi+feature_browser_emulation – David Heffernan Jun 01 '15 at 07:25
  • ahem ... "You cannot ask the WB control to use a different browser, it is hardwired to use the current version of Microsoft's Internet Explorer that is installed on the target computer." So maybe someone can explain to me why a registry patch needed to make it work with the currently installed version, which in this case is IE 11, if it's supposedly "hardwired" to use that version anyway? THIS is what I'm not understanding about this discussion. – David Schwartz Jun 01 '15 at 07:50
  • @DavidSchwartz: if you read the MS link I gave you, you will find this: 7000 (0x1B58) Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. **Default value for applications hosting the WebBrowser Control**. So even if you have the latest and greatest (its not) IE on your PC, it will be displayed in IE7 mode, unless you instruct it not doing so... – whosrdaddy Jun 01 '15 at 07:54
  • 1
    IE includes compatibility modes for earlier versions. So you'll be getting IE11 rendering in IE7 mode, say. Why are you so insistent that you know better? – David Heffernan Jun 01 '15 at 07:57
  • 1
    Why don't you listen to us. Your app can write to HKCU at startup. Your customers don't need to know about it. It's what I do. It works well. – David Heffernan Jun 01 '15 at 08:06
  • I haven't tested this, but you might be able to use RegOverridePredefKey in order to temporarily modify the registry for your program only. – Sebastian Z Jun 01 '15 at 08:32
  • @SebastianZ The value you set is named after the executable, so it's only going to affect your program – David Heffernan Jun 01 '15 at 08:35
  • My app sets a registry value at startup and TWebBrowser runs in an most recent IEEdge mode fine. See Feature_browser_emulation values http://stackoverflow.com/questions/29494269/twebbrowser-in-windows-10-microsoft-edge-formerly-spartan-internet-explorer/30391582#30391582 – Whome Mar 06 '16 at 11:32

2 Answers2

6

You are wondering whether your problems relate to Delphi version. Well the WebBrowser control is a system control. Delphi version is not relevant because the service is provided by the underlying system. If anything has changed it is likely to be the way You Tube delivers videos.

If you are crafting the HTML that embeds the remote video then you should follow the latest documentation from You Tube as to how it should be done. Don't use years old Delphi specific articles as your guide. Use modern articles specific to the latest technology used by You Tube.

I do have a feeling, although you don't state so in the question, that you are using an old and possibly deprecated method to embed a You Tube video. Use an iframe as described here: http://www.w3schools.com/html/html_youtube.asp


Adobe Flash Player or an HTML5 supported browser is required for video playback.

Your WebBrowser control will, in the absence of you taking specific steps otherwise, be using a legacy IE browser engine. So it won't have HTML5 support. And perhaps not even Flash support, that is if You Tube is still prepared to serve videos as Flash. Nowadays HTML5 is preferred. Not least because modern browser support it out of the box and there is no need for third party Flash plugin installation.

One way to opt in to using a modern HTML5 browser with the WebBrowser control is to make explicit registry settings (browser feature emulation), and perhaps specify a DOCTYPE. More details here: How to have Delphi TWebbrowser component running in IE9 mode? Although that question specifically asks about IE9, the documentation links in the answer provide details for other IE versions.

If you don't have control over the HTML document then you will need to use the above method.

On the other hand, if you do control the content of the HTML document then there is another way. You can place this

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

as the first item in your page's <head>. The meaning of edge is the latest version of IE. If you wish to target a specific version, e.g. IE9 then you would use:

<meta http-equiv="X-UA-Compatible" content="IE=9" />

More info on this here:

Older versions of IE do not support this header and if you need to cater for them then you are back to browser feature emulation in the registry. Thanks to @whosrdaddy and @TLama in the comments, it seems that IE8 introduced support for X-UA-Compatible.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • That other SO article (http://stackoverflow.com/questions/3931487/is-there-any-other-way-to-view-youtube-video-on-delphi) has no comments on the question, two clear answers, and no mention of having to fiddle with the registry. Telling users they have to edit their registry to make this work is simply unacceptable. If that's the only option, then I fail to see how Delphi has managed to get to XE8 with nobody making noise over this issue that seems to be unable to deal with something that ought to be simple to address. – David Schwartz Jun 01 '15 at 07:08
  • I suggest that you take your concerns up with Microsoft. None of us here can change Windows. – David Heffernan Jun 01 '15 at 07:10
  • What you're saying is that a standard install of the latest version of Delphi XEx into the latest version of Windows will BY DEFAULT use an ancient version of IE OCX from IE6 or IE7 when you utilize the TWebBrowser component, and that for TWebBrowser to work with the latest version, the developer must instruct his customers to edit their registry??? I'm sorry, but I simply do not buy this. – David Schwartz Jun 01 '15 at 07:16
  • 1
    As I explained in my answer, this is a system component. Delphi is not relevant here. I already linked to the component's documentation. Instead of getting irate I suggest you read that documentation, and my answer. I'm not enjoying this exchange, or your attitude. – David Heffernan Jun 01 '15 at 07:19
  • 1
    David is right. The IE behavior is completely unrelated to Delphi. I suppose MS has some good reasons that IE runs in IE7 mode by default and if you want to change that behavior you have to fiddle with the registry – iamjoosy Jun 01 '15 at 07:34
  • 1
    @DavidSchwartz: Twebbrowser under Delphi is nothing more than a wrapper component for the IE webbrowser embedded control (like most of the VCL wraps [Microsoft's common control library](https://msdn.microsoft.com/en-us/library/windows/desktop/bb775493%28v=vs.85%29.aspx)) – whosrdaddy Jun 01 '15 at 07:40
  • 1
    @DavidSchwartz: if you don't agree with microsoft and do not mind to distrubute extra DLL's with your application, you can always use [TChromium embedded framework](https://code.google.com/p/delphichromiumembedded/) – whosrdaddy Jun 01 '15 at 07:43
  • 2
    @DavidHeffernan: it seems to me he has control of the webpage, adding meta tag `` should solve his problem... – whosrdaddy Jun 01 '15 at 08:03
  • @whosrdaddy I think you still have to set the browser emulation mode in the reg key. At least for the WebBrowser control. Am I wrong? – David Heffernan Jun 01 '15 at 08:11
  • 1
    No in that case, it is the document that decides the browser mode. – whosrdaddy Jun 01 '15 at 08:31
  • @whosrdaddy OK, you are right. Do you know which version of IE first supported `X-UA-Compatible`? – David Heffernan Jun 01 '15 at 08:35
  • 1
    From memory, I believe it was 9, but i could be wrong :) – whosrdaddy Jun 01 '15 at 08:37
  • 1
    @David, *As of Windows Internet Explorer 8, the httpEquiv attribute also supports a value of x-ua-compatible* ([`source`](https://msdn.microsoft.com/en-us/library/ms533876(v=vs.85).aspx)). – TLama Jun 01 '15 at 08:37
  • Thank you @whosrdaddy, that meta-tag DID enable the video to play! – David Schwartz Jun 01 '15 at 19:28
4

As stated before I belive using TWebBrowser is the wrong way arround, because you have to little control about you video. Because then you have control over the video playback you self.

*** NOTE ****

DIRECT streaming of YouTube videos breaks the terms of service

*** NOTE ****

As i prommised you I've made an example here of howto play a youtube video on a Wincontrol ex. TPanel.

Since the example includes code for parsing the youtube URL and code for parsing the sourcecode of the youtube page where the video is embedded I can not post the complete source code here. And you have to get it from this link here

I'll here go trough the main idea of my exampel.

first a screenshot of the final result: enter image description here

The first thins to is are to import the WindowsMediaPlayer system component (not to be confused with the one ships with Delphi) and save WMPLib_TLB.pas alon with the project source.

Next step is do declare a private instance of the class:

WindowsMediaPlayer: TWindowsMediaPlayer;

And in formCreate, create an instance af set it up:

procedure TMainform.FormCreate(Sender: TObject);
begin
  WindowsMediaPlayer := TWindowsMediaPlayer.Create(Panel2);
  WindowsMediaPlayer.Parent := Panel2;
  WindowsMediaPlayer.Align := TAlign.alClient;
  WindowsMediaPlayer.Visible := True;
  WindowsMediaPlayer.Settings.AutoStart := True;
  WindowsMediaPlayer.uiMode := 'none';

  with TYoutubeThread.Create('https://www.youtube.com/watch?v=7vkYiCdn834') do
    OnTerminate := YoutubeThreadTerminate;
end;

Next step is to create an TYoutubeThread. TYoutubeThread is a thread that will get the HTML sourcocode of the requested youtubepage and parse it in order to get the information about the embedded video. The sourcecode for this thread are to be found in the complete example.

When the thread terminates we need to setup the GUI :

procedure TMainform.YoutubeThreadTerminate(Sender: TObject);
var
  YoutubeThread: TYoutubeThread;
begin
  YoutubeThread := Sender as TYoutubeThread;
  if YoutubeThread = nil then
    exit;

  //The information list are sorted my number of pixels in the video
  FInformation := YoutubeThread.Youtube.Informations.Last;

  Caption := Format('%s %s (%dx%d)', [YoutubeThread.Youtube.Title, FInformation.Quality, FInformation.Size.cx, FInformation.Size.cy]);
  Panel1.Visible := True;
  Width := FInformation.Size.cx + 50;
  Height := FInformation.Size.cy + Panel1.Height + 50;
  WindowsMediaPlayer.URL := FInformation.VideoLink;

  TrackBar1.Max := 0;
end;

Ive omitted two units, they can be downloded here http://pastebin.com/TqCUV9tg and here http://pastebin.com/WFGctwrf. And you'll lso need a copy of SuperObject

Or you could download the complete working example here

Jens Borrisholt
  • 6,174
  • 1
  • 33
  • 67
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/79440/discussion-on-answer-by-jens-borrisholt-how-to-embed-youtube-videos-in-newer-ver). – Taryn Jun 02 '15 at 16:19