|
Quick links:
F-IN-BOX Delphi Edition Help >> TFlashPlayerControl / TTransparentFlashPlayerControl >> Globals SetGlobalOnLoadExternalResourceHandlerEx
Syntax
[ Delphi ]
TFlashPlayerControlOnGlobalLoadExternalResourceEx = procedure(const URL: WideString; Stream: TStream; out bHandled: Boolean) of object; procedure SetGlobalOnLoadExternalResourceHandlerEx(Handler: TFlashPlayerControlOnGlobalLoadExternalResourceEx); [ Builder C++ ]
typedef void __fastcall (__closure *TFlashPlayerControlOnGlobalLoadExternalResourceEx)( const System::WideString URL, Classes::TStream* Stream, /* out */ bool &bHandled); void __fastcall SetGlobalOnLoadExternalResourceHandlerEx(TFlashPlayerControlOnGlobalLoadExternalResourceEx Handler); 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):
Read more here: Features
[ 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 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;
[ Builder C++ ]
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;
}
Copyright © 2004 - 2009 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. |