Medialooks Knowledge Base Support Center

Contact Us

Configuring preview

Preview is handled by MPreview (MPlatform SDK) and MFPreview (MFormats SDK) objects. Both objects use methods with the names and parameters, and the process of initialization is the same for both SDKs.

Initialization and setup a preview object

To configure it you should create an instance of this object:

MFPreview myPreview = new MFPreview(); // use MPreview for MPlatform SDK

The main methods for preview are PreviewEnable and PreviewWindowSet.
PreviewEnable enables audio and video preview that manages the object to operate audio and/or video data from a source for preview:

int enableAudio = 1;
int enableVideo = 1;
myPreview.PreviewEnable("", enableAudio, enableVideo);

PreviewWindowSet connects a control on a form of your application to draw frames by using DirectX on the control surface. It requires a handle of the control:

myPreview.PreviewWindowSet("", myPanelPreview.Handle.ToInt32());

If you don't call this method and enables video preview a new window will be created by the system itself and it will be used for preview.

All IMPreview methods contain _bsChannelID parameter as the first one. This parameter is reserved for future usage and at the moment it is ignored.

If you work with WPF or any other system where controls have no handles to connect to the object, please refer to this article about WPF preview.

Changing a cursor type on preview

To show a user the process state or do make it more user-friendly to understand the process sometimes it is useful to change the cursor type. For example, for resizing or dragging operation it is useful to show a cursor that matches the operation.

To do it, you can call PreviewSetCursor method:

myPreview.PreviewSetCursor("", eMCursorType.eMCT_CROSS);

Output a source to the preview

MPlatform SDK

(myPreview as IMObject).ObjectStart(mySourceObject);

MFormats SDK

MFFrame myFrame;
// grab a frame
((IMFSource)myLiveSource).SourceFrameGet(-1, out myFrame, "");
// send to the preview
((IMFReceiver)myPreview).ReceiverFramePut(myFrame, -1, "");

MPlatform SDK additional information

Source objects (MFile, MMixer, MPlaylist) supports IMPreview interface so you can configure a preview without an extra MPreview device:

m_objFile = new MFileClass();
//Initialize preview
m_objFile.PreviewWindowSet("", panelPreview.Handle.ToInt32());
m_objFile.PreviewEnable("", 1, 1);
//Set new file for playback
m_objFile.FileNameSet(pathToFile, extraProps);
//Start playback and preview
m_objFile.FilePlayStart();