FPC_AddOnLoadExternalResourceHandler
Syntax
typedef HRESULT (WINAPI *PLOAD_EXTERNAL_RESOURCE_HANDLER)(
LPCTSTR lpszURL,
IStream** ppStream,
HFPC hFPC,
LPARAM lParam);
DWORD WINAPI FPC_AddOnLoadExternalResourceHandler(
HFPC hFPC,
PLOAD_EXTERNAL_RESOURCE_HANDLER pHandler,
LPARAM lParam);
Description
The FPC_AddOnLoadExternalResourceHandler
function registers a callback that is triggered when Flash attempts to load an external resource by full path (e.g., FLV, JPEG, XML).
Applications can provide custom content either by assigning a new IStream or by writing data into the provided IStream.
The function returns a handler cookie that should later be removed with FPC_RemoveOnLoadExternalResourceHandler.
Usage Modes
-
Return
S_OK
and assign a new IStream Provide your own stream object to Flash. -
Return
S_OK
and write into the provided IStream Write resource content directly into the given stream. Do not release it. -
Return
S_ASYNCHRONOUS
Provide data asynchronously in a separate thread usingCoMarshalInterThreadInterfaceInStream
. If the stream'sWrite
method does not returnS_OK
, stop loading (e.g., another movie is being loaded or the Flash player is closing).
Example: Assigning a New IStream
m_dwHandlerCookie =
FPC_AddOnLoadExternalResourceHandler(hFPC,
&OnLoadExternalResourceHandler,
0);
HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam)
{
HRESULT hr = E_FAIL;
if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
{
IStream* pMemStream = NULL;
CreateStreamOnHGlobal(NULL, TRUE, &pMemStream);
while (...)
pMemStream->Write(...);
*ppStream = pMemStream;
hr = S_OK;
}
return hr;
}
Example: Writing into the Provided IStream
m_dwHandlerCookie =
FPC_AddOnLoadExternalResourceHandler(hFPC,
&OnLoadExternalResourceHandler,
0);
HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam)
{
HRESULT hr = E_FAIL;
if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
{
while (...)
(*ppStream)->Write(...);
hr = S_OK;
}
return hr;
}
Example: Asynchronous Content Delivery
m_dwHandlerCookie =
FPC_AddOnLoadExternalResourceHandler(hFPC,
&OnLoadExternalResourceHandler,
0);
HRESULT WINAPI OnLoadExternalResourceHandler(LPCSTR lpszURL, IStream** ppStream, HFPC hFPC, LPARAM lParam)
{
if (0 == lstrcmpiA(lpszURL, "http://FLV/FlashVideo.flv"))
{
IStream* pStream = *ppStream;
IStream* pStreamForMarshalling;
CoMarshalInterThreadInterfaceInStream(IID_IStream, pStream, &pStreamForMarshalling);
DWORD dwThreadId;
HANDLE hThread = CreateThread(NULL, 0, &FlashContentProviderThread, (LPVOID)pStreamForMarshalling, 0, &dwThreadId);
CloseHandle(hThread);
return S_ASYNCHRONOUS;
}
return E_FAIL;
}
DWORD WINAPI FlashContentProviderThread(LPVOID lpParameter)
{
CoInitialize(NULL);
IStream* pStreamForMarshalling = (IStream*)lpParameter;
IStream* pStream;
CoUnmarshalInterface(pStreamForMarshalling, IID_IStream, (void**)&pStream);
while (...)
{
if (S_OK != pStream->Write(...))
break;
}
pStreamForMarshalling->Release();
pStream->Release();
CoUninitialize();
return 1;
}