juhara.com

  • Narrow screen resolution
  • Wide screen resolution
  • Decrease font size
  • Default font size
  • Increase font size
Home Articles Multimedia Programming Multimedia Player with DirectShow Part 2
Multimedia Player with DirectShow Part 2 PDF Print E-mail
Written by Zamrony P. Juhara   
Friday, 15 September 2006 21:30
Article Index
Multimedia Player with DirectShow Part 2
Getting Width and Height of Original Video
Demo application
All Pages
This tutorial continues previous tutorial, Multimedia Player with DirectShow Part 1. This time, we are going to discuss how to display video on our own window. We also discuss how to display video in fullscreen mode or windowed mode.

Displaying video on particular window.

If you already try multimedia player application in first part of the tutorial, you will get video displayed on their own window when playing a video file. Then how if we want to display the video, for example, on our own form?

Filter Graph Manager implements IVideoWindow interface. This interface is interface we use to manipulate how video get displayed. We can zoom video in 50%, 100%, 200% or any scales on particular window. Video can also be displayed in fullscreen.

To get pointer to this interface, we call QueryInterface of Filter graph manager

var FVideoWindow:IVideoWindow;

FFilterGraph.QueryInterface(IID_IVideoWindow,FVideoWindow);

If succeed FVideoWindow will be filled with pointer to IVideoWindow instance. To be able to display video on a window, the steps are as follows:

  1. Set video to target window handle. You can do that with put_Owner() method. Parameter of this function is window handle. DirectShow uses OAHWND type to refere to window handle. So window handle must be typecasted to OAHWND.
    var FWindowHandle:HWND;
    FVideoWindow.put_Owner(OAHWND(FWindowHandle));
  2. Change visibility status. To make video visible on window, we need to change visibility of video with put_visible() method of IVideoWindow. Its parameter is visibility in longbool type.
    FVideoWindow.put_visible(true);
    Note: window referred by FWindowHandle must be visible too to let video visible.
  3. Change Style of Window. Style of window is set with SetWindowStyle of IVideoWindow. Window need to be set to child window with WS_CHILD and to ensure video is not drawn outside window area, we need to useWS_CLIPSIBLINGS style.
    FVideoWindow.SetWindowStyle(WS_CLIPSIBLINGS or WS_CHILD);
  4. Change Position of video on Window. Video can be placed anywhere on window's clientarea with SetPosition() of IVideoWindow.
    var arect:TRect;

    aRect.Left:=0;
    aRect.Top:=0;
    aRect.Right:=ClientWidth;
    aRcet.Bottom:=ClientHeight;
    FVideoWindow.SetPosition(aRect.left,aRect.Top,aRect.Right,aRect.Bottom);
    Changing width and height cause zoom to happen if new width and new height is not same with width and height of the original video. Zoom doesn't count aspect ratio. If we need to zoom and maintain same aspect ratio, we must get width and height of the original video. How we retrieve these data will be discussed after this.

Displaying Video in Fullscreen

IVideoWindow has put_FullscreenMode() method that we can use to change mode to fullscreen or windowed. If it is true, video is shown in fullscreen mode, otherwise it is shown in windowed mode.

Fullscreen mode:

FVideoWindow.put_FullscreenMode(true);

Windowed mode:

FVideoWindow.put_FullscreenMode(false);

To get status of status of fullscreen mode,

var statusFull:longBool;
FVideoWindow.get_FullscreenMode(statusFull);

When we're in fullscreen mode, our application doesn't receive focus, so all messages will be sent to filter graph manager. To let our application receive messages even in fullscreen mode (so we can, for example, toggle fullscreen on/off), we need to intercept messages to our application with put_MesageDrain() of IVideoWindow.

put_MessageDrain() expects window handle that will handle messages.

FVideoWindow.put_MessageDrain(FHandleWindow);

To get window handle intercepting messages we use IVideoWindow.get_MessageDrain().

FVideoWindow.Get_MessageDrain(FHandleWindow);

Clean Up

After we finish with IVideoWindow, we must change visibility status to false. If we failed to do that, video will keep showing on the screen and user will not be able to get rid of it. After that, owner window must be set to null with put_Owner().

FVideoWindow.put_Visible(false);
FvideoWindow.put_Owner(0);


Last Updated on Friday, 06 November 2009 15:29
 

Language

IndonesianEnglish (United Kingdom)

Game Institute
DAZ3D

Is this article helpful? Help this site improve by donating. Any amount is appreciated.