How to embed YouTube videos in newer versions of Delphi? - delphi

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.

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:
https://msdn.microsoft.com/en-us/library/ms533876.aspx
https://www.modern.ie/en-gb/performance/how-to-use-x-ua-compatible
How to put the WebBrowser control into IE9 into standards?
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.

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:
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

Related

Android application and read the web page

I have a question about the webbrowser component
Sow you change platform (mobile) devices note opens page
Display
Page Web note fond
Android path :Assets\internal\
thanks
EDIT: Code from comment
Var MS:tmemorystream;
Begin
Ms:=tmemorystream.create;
Ms.loadfromfile(gethomepath+pathdelim+'name.html');
Ms.postion:=0;
Ms.savetofile(opendilog .filename);
Webbrowser.navigate(opendilog.filename or 'name.html');
end;
assets\internal is not a path that your device can access. It's a path setting used by the deployment manager. To properly access that folder you must use
System.IOUtils.TPath.GetDocumentsPath
which points to the same folder that assets\internal points to.
The documentation for that is here http://docwiki.embarcadero.com/RADStudio/Rio/en/Standard_RTL_Path_Functions_across_the_Supported_Target_Platforms

How to make a basic Media player to play a video in avi format?

I want to play a video in Delphi.
This is the code that I've got:
if OpenDialog1.Execute then
begin
MediaPlayer1.FileName:=OpenDialog1.FileName;
MediaPlayer1.Open;
MediaPlayer1.Display:=pnlVideo;
MediaPlayer1.Play;
end;
But I get an error message:'The specified file cannot be played on the specified MCI device.The file may be corrupt, not in the correct format or no available file handler available for this format.'
The format of the video that I use is avi.
All help is appreciated.
There is a compatibility issue with the media player component in Delphi on our "modern" computers. I'm not tech savvy on what exactly the problem is :P. It is best to make your own component in Delphi to play media.
This link can help you make a Windows Media Player component, or you can adjust it to make another active X media player component - such as VLC.
https://chapmanworld.com/windows-media-player-in-delphi/
I hope this will help. :D

Delphi: Play mp4 file using DSPack

I have been playing around with DSPack, it can play avi and wmv files, but it is not playing mp4 files. i have installed ffdshow codec but still it wont play any other format. I read somewhere that i need to use ffdshow filter, but there is very limited documentation on how to do so... Can someone help me out here?
Edit
Thats the error i get when playing any other format
raised exception class EDirectShowException with message 'C ($80040265).'. Process stopped. Use Step or Run to continue.
and thats the function which pops the exception
function CheckDSError(HR: HRESULT): HRESULT;
var Excep: EDirectShowException;
begin
Result := HR;
if Failed(HR) then
begin
Excep := EDirectShowException.Create(format(GetErrorString(HR)+' ($%x).',[HR]));
Excep.ErrorCode := HR;
raise Excep;
end;
end;
Edit
I installed the haali demultiplexer, it was a self installer after installation i still get the same error. and the gdcl demultiplexer, those are two dll files, any suggestions on how to use them?
PS: I have never worked with codecs and/or this kind of stuff, so sorry for being so thick, And i am using Windows 7 x64
I can successfully play *.mp4 files with the "DSVideoWinDowEx\PlayWin" demo application that ships with DSPack. Windows 7 includes the mp4 codec, so this should not be an issue. Make sure that you're not running your application in debug mode, because many codecs refuse to work if a debugger is active.
The Haalie Media Splitter is not used for my test *.mp4 files. But it uses the AC3Filter. So your problem could also be a missing audio codec.
If that doesn't fix the issue then the question might be: "Why does it not work on your PC?"
In order to further narrow down the issue try playing the video with GraphEdit or GraphStudio and see if that works. These tools will also show the filter graph that is used. You can also show the FilterGraph that is used in your DSPack application.
If you install a DirectShow filter (codec) on your system, it will be used automatically by DirectShow/DSPack. You could register a filter in the system manually by calling regsvr32 "path_to_codec.ax", but this is usually done by the installer. It is possible to manually use a filter in DirectShow, but most of the time this is not needed.
lavfilters provide everything you will need with source splitters and decoders. It's open source, actively developed and based on ffmpeg. If you can't playback the mp4 after installing lavfilters then I would say there is a problem with the mp4 itself. In this case use something like ffprobe to inspect the file or post a link to the file.

Delphi TWebBrowser error

I am developing an iOS app using Delphi XE5 FireMonkey (with Update 1).
I download PDFs and store them locally and view them with a TWebBroswer. This always works the first time I download a document, or when viewing an already downloaded PDF. However, if I download and view a second PDF, the TWebBrowser does not load the file.
if FileExists(filename) then
begin
WebBrowser1.Navigate('about:blank'); //clear page
WebBrowser1.Navigate('file://' + filename);
//filename points to a PDF on the local device and the file
//definitly exists
//first run always works 100%, second run comes into this IF statement
//but the DidFailLoadWithError is fired
end;
I am trying to determine what the error is. Placing a try...except around the Navigate does not work, and the DidFailLoadWithError does not allow one to find the error.
See: http://qc.embarcadero.com/wc/qcmain.aspx?d=115652 for information on the DidFailLoadWithError 'bug'
procedure Tform1.WebBrowser1DidFailLoadWithError(ASender: TObject);
begin
//ASender is a TWebBrowser
//No parameter with Error info!
end;
Any suggestions as to how I can determine the error that is returned?
You'll need to make a copy of the FMX source directory, add that directory to your search path and make some tweaks to a couple of files.
When you next build your project it will recompile all those FMX units you copied/tweaked. You may be able to get away with copying just the one(s) you modify, and maybe a couple more via trial and error, which will make the initial build rather quicker.
In the FMX.WebBrowser.iOS procedure TiOSWebViewDelegate.webView() method, take the error parameter and do what is needed to get the error string from it, which basically amounts to calling the localizedDescription method, and pass it along to a call to NSLog. Documentation is here.
Then you can read the error message in the log, either in Console.app on OS X if using the iOS simulator, or in the Console section for your device in the Organizer window of Xcode if using an actual iOS device.

Sending an email from Delphi using Indy changes Danish chars

I have made a form that I use to send a mail using Indy. The form can be used to attach files as well.
All this is working very fine when I use the sample in the link below and when I use it in a utility I have made for sending invoices made as PDF files from an Excel project.
The strange things begin to happen when I put it to use in a large application I have that uses UniDAC and DevExpress - then all of a sudden my Danish chars in emailbody is gone. The are still present in the subject.
I haven't made any changes in the code and the form is executed in the same way as in the sample.
Any ideas as to what I should be looking for in order to get this working?
The sample can be downloaded here:
www.hugopedersen.dk/_guest/sendmail.zip
(some comments and text might be in Danish, but that should have no influence in how the code works)

Resources