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:
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.
You can expand a preview to a full-screen size with a PreviewFullScreen method with setting a screen index as a parameter that indicates what display to use for the full-sized preview (if you have several displays). For example, for the main display you should call:
myPreview.PreviewFullScreen("", 1, 0);
myPreview.PreviewIsFullScreen("", ref isFullScreen, ref screenIndex);
The method returns you whether the preview object is set for full-screen mode, and if it does (isFullScreen = 1) the screenIndex indicates an index of a display.
Changing a cursor type on preview
To show a user the process state or to 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:
Output a source to the preview
(myPreview as IMObject).ObjectStart(mySourceObject);
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();