[Demo] How to insert YouTube video in the editor

Demos, code samples. Only questions related to the existing topics are allowed here.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Demo] How to insert YouTube video in the editor

Post by Sergey Tkachenko »

This demo shows how to insert a YouTube video in a Delphi application using TRichViewEdit:
youtube.zip
(3.3 KiB) Downloaded 2554 times
This demo uses "Shockwave Flash" ActiveX (as TShockWaveFlash component).

The user enters the video URL (in the form http://www.youtube.com/watch?v=VIDEOID). The program creates TShockWaveFlash control and assign its Movie property to play the specified video.

Update: Unfortunately, the result now looks like this:
watch-on-youtube.png
watch-on-youtube.png (180.65 KiB) Viewed 56847 times
But when exported in HTML and viewed in a browser, it looks correctly.

[+] History of updates
2018-Apr-21: for compatibility with TRichView 17.3. Also, format of YouTube URL is updated (HTTPS is accepted).
[+] Old versions
http://www.trichview.com/support/files/youtube.zip - for TRichView 17.2 and older
ekoindri
Posts: 19
Joined: Sun May 30, 2010 10:00 pm
Location: Indonesia

Post by ekoindri »

Could you show me how to save TRichViewEdit + Youtube to HTML file?

Is this possible to be done?
If this can be realized, it will be so amazing.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use OnSaveComponentToFile event:

Code: Select all

procedure TForm1.RichViewEdit1SaveComponentToFile(Sender: TCustomRichView;
  Path: String; SaveMe: TPersistent; SaveFormat: TRVSaveFormat;
  var OutStr: String);
begin
  if (SaveFormat=rvsfHTML) and (SaveMe is TShockwaveFlash) then begin
     OutStr := Format(
       '<object width="%d" height="%d">'+
        '<param name="movie" value="%s"></param>'+
        '<param name="allowFullScreen" value="true"></param>'+
        '<param name="allowscriptaccess" value="always"></param>'+
        '<embed src="%s" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="%d" height="%d"></embed>'+
       '</object>',
         [TShockwaveFlash(SaveMe).Width, TShockwaveFlash(SaveMe).Height,
          TShockwaveFlash(SaveMe).Movie,
          TShockwaveFlash(SaveMe).Movie,
          TShockwaveFlash(SaveMe).Width, TShockwaveFlash(SaveMe).Height]);
  end;
end;
ekoindri
Posts: 19
Joined: Sun May 30, 2010 10:00 pm
Location: Indonesia

Post by ekoindri »

@Sergey Tkachenko

Wow...your code above work properly.
Now, I have a problem.
When I sent it via email and I open it with Microsoft OutLook, I can not see
the youtube. What I have to do in order to see the video from email.

Actually, I want to send mass email to my friends and they can see the
video when open the email.

Do you think that this issue is possible to be done by TRichView?
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I am afraid no, this problem cannot be solved in TRichView.
Either Outlook does not support flash objects, or some (security) settings must be changed in it to view youtube videos.
Sorry, I do not use Outlook myself.
ekoindri
Posts: 19
Joined: Sun May 30, 2010 10:00 pm
Location: Indonesia

Post by ekoindri »

@Sergey Tkachenko

Thanks for your explanation. You're right, MS OutLook does not support for
showing the youtube video directly. It seems that I have to create it by
myself, so I do not need to use Microsoft Outlook anymore.

Any way, your code above has provided me a hint so useful to achieve this
issue.

regards,


Eko Indriyawan
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Just tried this demo on Delphi 2010 under Windows 7 x64 with Adobe Flash 10.2 installed.
It works but during insert I'm getting some EInvalidOp with message 'Invalid floating point operation' errors and Access violation at address 608C89B1 in module 'Flash10o.ocx'. Write of address 0000566D.
Didn't check the code yet just wanted to inform about these errors.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Also when I close application with YouTube inside RVE I'm getting AccessViolation again. But YouTube plays and inserts fine.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In my tests, calling RichViewEdit1.Clear in FormClose fixed the problem with error on closing.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

If you click Flash control before it's completely loaded you'll get some Invalid Pointer operation errors, access violations etc...
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you have ideas how to fix it? AFAIK, these problems are not related to our components
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Actually I don't know how to fix it yet. Will try to find a way.
Never worked with ActiveX (I think it's a bad thing) but maybe there is a way to check when somebody clicks on flash control and put some try-except routines...
Actually did you get the same errors clicking on flash?
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I tried. No, I do not get errors when I click the object immediately after creating it.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Try to click several times... I just tried again and got (from 3-4th click):

Code: Select all

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EInvalidOp with message 'Invalid floating point operation'.
---------------------------
Break   Continue   Help   
---------------------------
AND

Code: Select all

---------------------------
Project
---------------------------
Access violation at address 5DE389B1 in module 'Flash10o.ocx'. Write of address 0000566D.
---------------------------
OK   
---------------------------
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I cannot reproduce, no matter how many times I click :(
Post Reply