Using HTML as a Source
You can use HTML Web content as a source, which allows you to stream HTML (for example, a PowerPoint presentation consisting of HTML slides and JPG images) in a synchronized metered delivery over the Internet or a network. This feature delivers HTML content inside the stream, which is then delivered to the Internet file cache on the viewer's computer. The URLs to the content are delivered to the player. The HTML content is delivered in advance, so when the presentation advances to the next slide, the page and its images are already on the viewer's computer and there is no delay in the presentation. This feature also accommodates viewers who connect to the presentation in progress, because HTML content is continually delivered in the stream, allowing the viewer to receive the next slide.
HTML content is sent in sets of files, with the main file sent first. File sets can be sent at specific times or can be sent manually. You can also add a script source so you can send script commands to the player during the presentation.
The recommended way to display streaming HTML is by embedding a player object in a Web page, which is opened by the end user. One part of the page is the audio and video presentation (such as a live speaker), and the other part consists of Web pages and images, as shown in the following diagram.
When using HTML as a source, consider the following:
- You must create a special profile for use with an HTML source. Specifically, you must add HTML as a content type, specify the bit rate for the HTML stream, and specify the preroll setting. The preroll setting specifies how far in advance (in milliseconds) to send HTML content. You determine the value of this setting according to the largest HTML file in your collection and the bit rate you specify. A preroll setting that is too small might prevent files from being transferred or might cause the stream to be out of synch.
- To allow viewers to join a stream in progress, set the repeat setting on the HTML source to true (see IWMEncSource). This setting causes the HTML stream to be sent repeatedly; however for a better viewing experience, consider adding code to the Web page to prevent the user's screen from being continually refreshed. For example, only display a URL if it has not been viewed already. You can also use script to control the display for users that join a stream in progress. For more information, see Using Script to Control URL Flipping in the Windows Media Player 9 Series SDK.
- Consider preventing the embedded player from launching new Web browser windows for each URL received. For an embedded Windows Media Player, this setting is
<param NAME="invokeURLs" VALUE="-1">
.
Use IWMEncFileSet to add HTML content to include in the stream, and specify when to send it. Use IWMEncFileTransferSource to group and arrange the HTML content, and to send it.
The following example shows how to start a broadcast and send the first HTML file set. For end-to-end code examples, see Complete Code Examples.
Visual Basic Example
' Create a WMEncoder object.
Dim Encoder As WMEncoder
Set Encoder = New WMEncoder
' Retrieve the source group collection and add a source group.
Dim SrcGrpColl As IWMEncSourceGroupCollection
Dim SrcGrp As IWMEncSourceGroup2
Set SrcGrpColl = Encoder.SourceGroupCollection
Set SrcGrp = SrcGrpColl.Add("SG_1")
' Add an audio, video, and HTML source.
Dim SrcAud As IWMEncAudioSource
Dim SrcVid As IWMEncVideoSource
Dim SrcHTML As IWMEncSource
Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
Set SrcHTML = SrcGrp.AddSource(WMENC_FILETRANSFER)
' Use the default audio and video devices.
SrcAud.SetInput ("Device://Default_Audio_Device")
SrcVid.SetInput ("Device://Default_Video_Device")
' The HTML scheme is FileTransfer, and the resource string is not used.
SrcHTML.SetInput ("FileTransfer://placeholdertext")
' Set the HTML stream to repeat.
SrcHTML.Repeat = True
' Continue configuring the encoding session, including the profile
' and broadcast settings.
' Start encoding.
Encoder.Start
' Retrieve the file transfer plug-in from the HTML source.
Dim pUnkFileSrcPlugin As IUnknown
Set pUnkFileSrcPlugin = SrcHTML.GetSourcePlugin
Dim FileTransSrc As IWMEncFileTransferSource
Set FileTransSrc = pUnkFileSrcPlugin
' Create a file set, add HTML content, and then send it.
Dim FileSet As IWMEncFileSet
Set FileSet = FileTransSrc.Add
FileSet.Add "C:\HTML\image.jpg", "https://YourWebSite/image.jpg"
FileTransSrc.Send FileSet
C++ Example
// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"
#include <conio.h> // for kbhit()
HRESULT hr;
IWMEncoder2* pEncoder;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp1;
IWMEncSourceGroup2* pSrcGrp;
IWMEncSource* pSrcAud;
IWMEncSource* pSrcVid;
IWMEncSource* pSrcHTML;
IWMEncFileSet* pFileSet;
IWMEncFileTransferSource* pFileTransSrc;
IUnknown* pUnknown;
CComBSTR bstrName = NULL;
long lCount;
int i;
// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder2,
(void**) &pEncoder);
}
// Retrieve the source group collection.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}
// Add a source group named SG1 to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp1);
}
// Retrieve a pointer to an IWMEncSourceGroup2 interface.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp1->QueryInterface(IID_IWMEncSourceGroup2, (void**)&pSrcGrp);
}
// Add sources to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrcVid);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_FILETRANSFER, &pSrcHTML);
}
// Add an audio and a video source to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcAud->SetInput(CComBSTR("Device://Default_Audio_Device"));
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR("Device://Default_Video_Device"));
}
// The HTML scheme is FileTransfer, and the resource string is not used.
if ( SUCCEEDED( hr ) )
{
hr = pSrcHTML->SetInput(CComBSTR("FileTransfer://placeholdertext"));
}
// Set the HTML stream to repeat.
if ( SUCCEEDED( hr ) )
{
hr = pSrcHTML->put_Repeat(VARIANT_TRUE);
}
// Initialize the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}
// Retrieve the file transfer plug-in from the HTML source.
if ( SUCCEEDED( hr ) )
{
hr = pSrcHTML->GetSourcePlugin(&pUnknown);
}
if ( SUCCEEDED( hr ) )
{
hr = pUnknown->QueryInterface(IID_IWMEncFileTransferSource, (void**) &pFileTransSrc);
}
// Specify user driven mode (rather then sending files at specific times).
if ( SUCCEEDED( hr ) )
{
hr = pFileTransSrc->put_UserDrivenMode(VARIANT_TRUE);
}
// Start encoding.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
// Create a new file set, add HTML content to it, and then send it.
if ( SUCCEEDED( hr ) )
{
hr = pFileTransSrc->Add(&pFileSet);
}
if ( SUCCEEDED( hr ) )
{
hr = pFileSet->Add(CComBSTR("C:\\HTML\\image1.jpg"), CComBSTR("C:\\HTML\\image1.jpg"));
}
if ( SUCCEEDED( hr ) )
{
hr = pFileTransSrc->Send(pFileSet);
}
// Send the second HTML file.
printf("Press a key to send another HTML file.\n");
// Wait for a key press.
while(!kbhit())
_asm nop;
// Create a new file set, add HTML content to it, and then send it.
if ( SUCCEEDED( hr ) )
{
hr = pFileTransSrc->Add(&pFileSet);
}
if ( SUCCEEDED( hr ) )
{
hr = pFileSet->Add(CComBSTR("C:\\HTML\\image2.jpg"), CComBSTR("C:\\HTML\\image2.jpg"));
}
if ( SUCCEEDED( hr ) )
{
hr = pFileTransSrc->Send(pFileSet);
}
// Stop encoding.
printf("Press a key to stop encoding.\n");
// Wait for a key press.
_getch();
while(!kbhit())
_asm nop;
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Stop();
}
// Release pointers.
if ( pFileSet )
{
pFileSet->Release();
pFileSet = NULL;
}
if ( pFileTransSrc )
{
pFileTransSrc->Release();
pFileTransSrc = NULL;
}
if ( pSrcHTML )
{
pSrcHTML->Release();
pSrcHTML = NULL;
}
if ( pUnknown )
{
pUnknown->Release();
pUnknown = NULL;
}
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pSrcGrp1 )
{
pSrcGrp1->Release();
pSrcGrp1 = NULL;
}
if ( pSrcAud )
{
pSrcAud->Release();
pSrcAud = NULL;
}
if ( pSrcVid )
{
pSrcVid->Release();
pSrcVid = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
See Also