You can intercept and provide content of external resource a flash movie are loading. For instance, Flash Video.
To play Flash Video from memory you should create flash movie that loads Flash Video from "private" URL (e.g., "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");
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, FlashPlayerControl provides content of FLV. Use function FPCSetGlobalOnLoadExternalResourceHandler to set handle the external resources and provide them to Flash. See the code:
[ C++ ]
- HRESULT WINAPI GlobalOnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream);
- ...
- FPCSetGlobalOnLoadExternalResourceHandler(&GlobalOnLoadExternalResourceHandler);
- ...
- HRESULT WINAPI GlobalOnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream)
- {
- HRESULT hr = E_FAIL;
-
- if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
- {
-
- IStream* pMemStream = NULL;
- CreateStreamOnHGlobal(NULL, TRUE, &pMemStream);
-
-
- HMODULE hModule = GetModuleHandle(NULL);
- HRSRC hResInfo = FindResource(hModule, _T("EMBEDDED_FLV"), _T("FLV"));
- HGLOBAL hResData = LoadResource(hModule, hResInfo);
- LPCVOID lpData = LockResource(hResData);
- DWORD dwSize = SizeofResource(hModule, hResInfo);
-
- ULONG nWritten;
- pMemStream->Write(lpData, dwSize, &nWritten);
-
-
- LARGE_INTEGER liZero = { 0 };
- ULARGE_INTEGER ulNewPosition;
- pMemStream->Seek(liZero, STREAM_SEEK_SET, &ulNewPosition);
-
- *ppStream = pMemStream;
- hr = S_OK;
- }
-
- return hr;
- }
HRESULT WINAPI GlobalOnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream);
...
FPCSetGlobalOnLoadExternalResourceHandler(&GlobalOnLoadExternalResourceHandler);
...
HRESULT WINAPI GlobalOnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream)
{
HRESULT hr = E_FAIL;
if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
{
// Create stream
IStream* pMemStream = NULL;
CreateStreamOnHGlobal(NULL, TRUE, &pMemStream);
// Save flash video to the stream from the resource
HMODULE hModule = GetModuleHandle(NULL);
HRSRC hResInfo = FindResource(hModule, _T("EMBEDDED_FLV"), _T("FLV"));
HGLOBAL hResData = LoadResource(hModule, hResInfo);
LPCVOID lpData = LockResource(hResData);
DWORD dwSize = SizeofResource(hModule, hResInfo);
ULONG nWritten;
pMemStream->Write(lpData, dwSize, &nWritten);
// Seek stream position to the begin
LARGE_INTEGER liZero = { 0 };
ULARGE_INTEGER ulNewPosition;
pMemStream->Seek(liZero, STREAM_SEEK_SET, &ulNewPosition);
*ppStream = pMemStream;
hr = S_OK;
}
return hr;
}