Streaming Support
Streaming allows Flash content to be loaded asynchronously. This is useful for large movies or when resources such as SWF, FLV, JPG, MP3, or XML files must be provided progressively. Instead of waiting until the entire file is available, the content can be written into a stream in parts while playback continues.
Key Notes
- To load movies or resources, use a stream (
TStream
). Provide content by writing to the stream. - If data is written from a separate thread, use
Synchronize
when callingWrite
. - If
Write
returns 0, loading was canceled (for example, another movie is being loaded). - Free the stream after loading is complete, even if canceled.
Use Cases
Loading a Movie Asynchronously
Use LoadMovieUsingStream or PutMovieUsingStream to begin asynchronous loading.
Delphi Example:
var
MovieStream: TStream;
begin
FlashPlayerControl1.LoadMovieUsingStream(0, MovieStream);
ContentProviderThread := TContentProviderThread.Create(MovieStream);
end;
procedure TContentProviderThread.Execute;
begin
while not FStop do
begin
PrepareBuffer;
if FBuffer.Size > 0 then
DoWrite;
end;
FMovieStream.Free;
end;
C++Builder Example:
TStream* MovieStream;
FlashPlayerControl1->LoadMovieUsingStream(0, MovieStream);
TContentProviderThread* ContentProviderThread = new TContentProviderThread(MovieStream);
void __fastcall TContentProviderThread::Execute()
{
while (!FStop)
{
PrepareBuffer();
if (FBuffer->Size > 0)
DoWrite();
}
FMovieStream->Free();
}
Loading External Resources by Full Path
To provide resources such as *.flv
, *.swf
, *.jpg
, or *.mp3
from a full path (for example, beginning with http://
), set a global handler using SetGlobalOnLoadExternalResourceHandlerEx.
In the handler, compare the URL, mark the request as handled, and write data into the provided stream.
Loading External Resources by Relative Path
When a movie loads resources by relative path (e.g., images/image1.jpg
), handle the OnLoadExternalResourceEx event.
Check the passed URL, mark the request as handled, and provide the resource through the stream.
Delphi Example:
procedure TMainForm.FlashPlayerControl1LoadExternalResourceEx(
ASender: TObject;
const URL: WideString;
Stream: TStream;
var bHandled: Boolean);
begin
if URL = 'images/embedded_image1.jpg' then
begin
ContentProviderThread := TContentProviderThread.Create(Stream);
bHandled := true;
end;
end;
C++Builder Example:
void __fastcall TMainForm::FlashPlayerControl1LoadExternalResourceEx(
TObject *ASender,
const WideString URL,
TStream *Stream,
BooleanRef bHandled)
{
if (URL == WideString("images/embedded_image1.jpg"))
{
TContentProviderThread* ContentProviderThread = new TContentProviderThread(Stream);
*bHandled = true;
}
}