F-IN-BOX Delphi Edition Help >> TFlashPlayerControl / TTransparentFlashPlayerControl >> Globals

SetGlobalOnLoadExternalResourceHandler

Syntax

[ Delphi ]
procedure SetGlobalOnLoadExternalResourceHandler(Handler: TFlashPlayerControlOnGlobalLoadExternalResource);
TFlashPlayerControlOnGlobalLoadExternalResource = procedure(const URL: WideString; Stream: TStream) of object;

[ Builder C++ ]
void __fastcall SetGlobalOnLoadExternalResourceHandler(TFlashPlayerControlOnGlobalLoadExternalResource Handler);

Remark

From version 3.1 the argument URL has been changed to WideString (in previous versions the type was AnsiString / string).

Description

You can intercept and provide content of external resource a flash movie are loading. For instance, Flash Video. To play Flash Video from stream you should create flash movie that loads Flash Video from "private" URL (http://FLV/FlashVideo.flv). Flash Movie uses the following code to load Flash Video (put this in under a button in your Swf Flash Movie):

[ ActionScript ]
var netConn:NetConnection = new NetConnection();
netConn.connect(null);
var netStream:NetStream = new NetStream(netConn);
my_video.attachVideo(netStream);
netStream.setBufferTime(0);
netStream.play("http://FLV/FlashVideo.flv");

When Flash tries to load Flash Video from http://FLV/FlashVideo.flv, TFlashPlayerControl provides content of FLV. Use global procedure SetGlobalOnLoadExternalResourceHandler to set handle the external resources and provide them to Flash. See the code:

[ Delphi ]
type
  TMainForm = class(TForm)
    procedure FormCreate(Sender: TObject);
...

  private
    procedure OnGlobalLoadExternalResource(const URL: WideString; Stream: TStream);
...

end;
...

procedure TMainForm.FormCreate(Sender: TObject);
begin
    SetGlobalOnLoadExternalResourceHandler(OnGlobalLoadExternalResource);
end;
...

procedure TMainForm.OnGlobalLoadExternalResource(const URL: WideString; Stream: TStream);
var
  ResourceStream: TResourceStream;
begin
    if URL = 'http://FLV/FlashVideo.flv' then
    begin
        ResourceStream := TResourceStream.Create(0, 'FlashVideo', 'FLV');
        ResourceStream.SaveToStream(Stream);
        ResourceStream.Free;
    end;
end;

[ Builder C++ ]
class TMainForm : public TForm
{
__published:
        void __fastcall FormCreate(TObject *Sender);
...

private:
        void __fastcall OnGlobalLoadExternalResource(const WideString URL, Classes::TStream* Stream);
...

}
...

void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  SetGlobalOnLoadExternalResourceHandler(OnGlobalLoadExternalResource);
}
...

void __fastcall TMainForm::OnGlobalLoadExternalResource(const WideString URL, Classes::TStream* Stream)
{
  if (URL == WideString("http://FLV/FlashVideo.flv"))
  {
    TResourceStream* ResourceStream = new TResourceStream(0, "FlashVideo", "FLV");
    ResourceStream->SaveToStream(Stream);
    delete ResourceStream;
  }
}

More about TFlashPlayerControl
Copyright © Softanics. All rights reserved
F-IN-BOX is a registered trademark of Softanics|Delphi is a trademark of Borland Software Corporation|Macromedia and Shockwave Flash are trademarks of Adobe, Inc.