How do I embed YouTube videos in newer Delphi versions?

I am trying to upload a YouTube video to TWebBrowser in Delphi XE7 and I am getting the error:

Video playback requires Adobe Flash Player or a supported HTML5 browser.
Get the latest Flash Player
Learn more about HTML5 browser update

I can load normal HTML normally.

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

EDIT: My goal is to just download and play videos from a URL, like a YouTube video. Solutions other than TWebBrowser are great, especially if they can run cross-platform.

+3


source to share


2 answers


You are wondering if your problems are related to the Delphi version. Well, the WebBrowser control is a system control. Delphi version doesn't matter as the service is provided by the underlying system. If anything has changed, it will probably be the way You Tube provides video.

If you are creating HTML to embed a remote video, you should follow the latest You Tube documentation on how to do it. Don't use the summer specialty articles in Delphi as a guide. Use up-to-date articles related to the latest technology used by You Tube.

I have a feeling, although you are not so claiming in the question, that you are using an old and possibly outdated method for embedding a You Tube video. Use an iframe as described here: http://www.w3schools.com/html/html_youtube.asp


Video playback requires Adobe Flash Player or a supported HTML5 browser.

Your WebBrowser control will, unless you take specific action otherwise, use the legacy IE browser engine. Thus, it will not have HTML5 support. And maybe even Flash support, i.e. If You Tube is still ready to serve videos as Flash. HTML5 is currently preferred. Not least because a modern browser supports it out of the box and there is no need to install a third-party Flash module.

One way to get away with using the modern HTML5 browser with the WebBrowser control is to make explicit registry settings (emulate browser functionality) and possibly specify a DOCTYPE. More details here: How to use Delphi TWebbrowser component running in IE9 mode? While this question specifically asks about IE9, the documentation links in the answer provide details on other versions of IE.

If you have no control over the HTML document, you will need to use the above method.



On the other hand, if you are in control of the content of the HTML document, there is another way. You can post this

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

      

as the first element on your page <head>

. The value edge

is the latest version of IE. If you want to target a specific version, eg. IE9, then you will use:

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

      

More on this here:

Older versions of IE do not support this header, and if you need to serve them, you will fall back to emulating browser functionality in the registry. Thanks to the comments of @whosrdaddy and @TLama, IE8 has support X-UA-Compatible

.

+6


source


As said, I believe using TWebBrowser is the wrong way arround because you need a little control over your video. Because then you are in control of the video playback yourself.

*** NOTE ****

LIVE streaming YouTube video violates terms of service

*** NOTE ****

As I promised, I gave an example of a game to play YouTube videos on Wincontrol ex. TPanel.

Since the example includes code to parse the youtube url and code to parse the source of the youtube page where the video is embedded, I cannot post the complete source here. And you should get it from this link here

I will follow the main idea of ​​my exam.

first screenshot of the final result: enter image description here

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



Next step: declare a private instance of the class:

WindowsMediaPlayer: TWindowsMediaPlayer;

And in formCreate, create an instance of af configured for it:

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;

      

The next step is to create TYoutubeThread

. TYoutubeThread

is a stream that will receive the HTML sourcocode of the theme you requested and parse it to get information about the embedded video. The source code for this stream is contained in the complete example.

When the thread finishes, we need to configure 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 dropped two units, they can be downgraded here http://pastebin.com/TqCUV9tg and here http://pastebin.com/WFGctwrf . And you also need a copySuperObject

Or you can download a complete working example here

+4


source







All Articles