SetGlobalOnLoadExternalResourceHandlerEx
Syntax
Delphi
TFlashPlayerControlOnGlobalLoadExternalResourceEx = procedure(
const URL: WideString;
Stream: TStream;
out bHandled: Boolean) of object;
procedure SetGlobalOnLoadExternalResourceHandlerEx(Handler: TFlashPlayerControlOnGlobalLoadExternalResourceEx);
C++Builder
typedef void __fastcall (__closure *TFlashPlayerControlOnGlobalLoadExternalResourceEx)(
const System::WideString URL,
Classes::TStream* Stream,
/* out */ bool &bHandled);
void __fastcall SetGlobalOnLoadExternalResourceHandlerEx(TFlashPlayerControlOnGlobalLoadExternalResourceEx Handler);
Description
The SetGlobalOnLoadExternalResourceHandlerEx
procedure registers a global handler that allows you to intercept and provide the content of external resources requested by Flash movies.
Unlike SetGlobalOnLoadExternalResourceHandler, the Ex variant enables asynchronous streaming of content. This is useful for large resources such as Flash Video (FLV) files, where providing data incrementally avoids blocking the application and prevents Flash from preallocating excessive memory:
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 the Flash movie requests http://FLV/FlashVideo.flv, the registered handler is called. If bHandled
is set to True
, you can provide the content asynchronously through the provided Stream:
type
TMainForm = class(TForm)
procedure FormCreate(Sender: TObject);
// ...
private
procedure OnGlobalLoadExternalResourceEx(const URL: WideString; Stream: TStream; out bHandled: Boolean);
// ...
end;
TContentProvideThread = class(TThread)
protected
procedure Execute; override;
end;
// ...
procedure TMainForm.FormCreate(Sender: TObject);
begin
SetGlobalOnLoadExternalResourceHandlerEx(OnGlobalLoadExternalResourceEx);
end;
// ...
procedure TMainForm.OnGlobalLoadExternalResourceEx(const URL: WideString; Stream: TStream; out bHandled: Boolean);
var
ResourceStream: TResourceStream;
ContentProvideThread: TContentProvideThread;
begin
if URL = 'http://FLV/FlashVideo.flv' then
begin
bHandled := true; // Notify flash that we are ready to provide content
// Create new thread to provide data
ContentProvideThread := TContentProvideThread.Create(Stream);
end;
end;
// ...
procedure TContentProvideThread.Execute;
begin
// Copy data from source stream to Stream
ResourceStream := TResourceStream.Create(0, 'FlashVideo', 'FLV');
ResourceStream.SaveToStream(Stream);
ResourceStream.Free;
end;
class TMainForm : public TForm
{
__published:
void __fastcall FormCreate(TObject *Sender);
// ...
private:
void __fastcall OnGlobalLoadExternalResourceEx(const WideString URL, Classes::TStream* Stream, bool &bHandled);
// ...
}
// ...
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
SetGlobalOnLoadExternalResourceHandler(OnGlobalLoadExternalResource);
}
// ...
void __fastcall TMainForm::OnGlobalLoadExternalResource(const WideString URL, Classes::TStream* Stream, bool &bHandled)
{
if (URL == WideString("http://FLV/FlashVideo.flv"))
{
bHandled = true; // Notify flash that we are ready to provide content
// Create new thread to provide data
// class TContentProvideThread: public TThread so far...
TContentProvideThread* ContentProvideThread =
new TContentProvideThread(Stream);
}
}
...
void __fastcall TContentProvideThread::Execute()
{
TResourceStream* ResourceStream = new TResourceStream(0, "FlashVideo", "FLV");
ResourceStream->SaveToStream(Stream);
delete ResourceStream;
}