简体   繁体   中英

What is the right way to add buttons to the Media Foundation Interfaces video screen

I'm currently trying to build a player literally from scratch using Media Foundation Interfaces.

I use the example taken from here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd979592(v=vs.85).aspx

As the basis for the player.

I want to add buttons (back/forward button , progress bar etc.) to the video screen window, but it isn't so clear to me how.

I can not simply add a button as a child of the main window because it is hidden by the player, I tried to add the buttons as children of Video window but it did not work ...

What is the right way to add buttons to a video window?

This is part of the code where you register to the player window (to the full code please enter the link I have attached).

// create the instance of the player hwnd = handle of main window
HRESULT hr = CPlayer::CreateInstance(hwnd, hwnd, &g_pPlayer);

// inner call to cplayer
CPlayer *pPlayer = new (std::nothrow) CPlayer(hVideo, hEvent);

// Create a partial topology. (m_hwndVideo == hVideo == hwnd)
hr = CreatePlaybackTopology(m_pSource, pSourcePD, m_hwndVideo, &pTopology);

i try to use this function in order to change video paint so i will have some place left at the bottom to put there my buttons, here is my function:

VOID update_lower_window(HWND hwnd)
{
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(hwnd, &ps);

    RECT rc;
    GetClientRect(hwnd, &rc);

    //rc = father size
    RECT repaint;
    memcpy(&repaint, &rc, sizeof(RECT));
    repaint.top = repaint.bottom - DOWN_SPACE; // DOWN_SPACE == 50

    // paint back bottom to white
    FillRect(hdc, &repaint, (HBRUSH)COLOR_WINDOW);

    EndPaint(hwnd, &ps);
}

i call this function when:

  1. WM_PAINT happend
  2. WM_SIZE happend
  3. WM_CREATE happend

With this said I still could not achieve my goals:

  1. When the movie starts playing it starts full screen and does not leave the space I wanted down (I can not seem to find the message sent when the movie is played or in other words when the movie paint on the screen it's not sent one of the messages on which I inserted my function)
  2. When I reduce the screen, the remnants of the previous screen still remain down and I can't see the background.
  3. When using the Minimize button it get the same phenomenon as in 2.

Another interesting detail The phenomenon I mentioned in 2 occurs only when I change window size by drag from the bottom up, if I change window size by drag from one corner (enlarges or decreases height and width simultaneously) then the window corrects itself and I see in the bottom white part (the background) all the time.

You can reposition video area so your win32 GUI (buttons and progress) is below. See WM_SIZE handler in that sample for how to do it, they calculate rectangle to occupy the window, you can adjust to accommodate your controls.

If you want translucent overlaid controls you can write a EVR Presenter. https://msdn.microsoft.com/en-us/library/windows/desktop/bb530107(v=vs.85).aspx https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/multimedia/mediafoundation/evrpresenter

But that's relatively hard.

PS If you just want a simple solution, use something higher-level. Like Windows Media Player control note they have a C++ example, or .NET for GUI and MediaElement in it.

Update: I think the right place to set initial video position in that sample is likely CPlayer::OnTopologyStatus, after MFGetService(MR_VIDEO_RENDER_SERVICE) line.

Anyway, another approach that might be simpler for your task, create a child window dedicated to the video. Position it so it occupies the majority of your app's main window, and only leaves bottom 50px unoccupied. Don't forget to handle at least WM_SIZE to reposition and ideally also WM_DISPLAYCHANGED, WM_ENDSESSION, WM_GETMINMAXINFO. Setup the MF playback so that video occupies the complete child video window. This will ensure the video won't interfere with Win32 stuff you're painting on your bottom 50px panel.

BTW that's what MPC-HC is doing, see the pic. 在此处输入图片说明 As you see on Spy++ screenshot, they have dedicated video window, and also other child windows for Win32 controls of the player.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM