Using the Windows Media Player Control on Handheld Devices

Multimedia Support in Windows CE

Recently, facing up to the fact that Windows CE 5.0 is coming soon on real devices, it is wonderful to understand that PDAs already have their own history. Mobile technologies made unbelievable progress during the last 10 years. The very first Windows CE-powered devices were an adventure in terms of capabilities and programming. The only sign of multimedia features was an opportunity to play WAV files. The latest Windows CE handhelds come with Windows Media Player 10 Mobile, which has many wonderful features and is built on the same platform as its big desktop brother. Now, you may add rich multimedia support to your applications, including playing video and audio files, displaying pictures, and so forth. You will find additional information about available SDKs and other related topics in the “References” section at the end of this article.

This article doesn’t pretend to be a full guide for WMP SDK, far from this. My goal is to introduce WMP common techniques, so that you’ll be able to use them easily in your own code.

Windows Media Player Object Model Overview

WMSDK offers you a lot of different interfaces, but not all of them are supported on Windows Mobile platforms. Below, I’ve put together a short description of what you can use:

Interface Description
IWMPCore Root interface of WMP object model. You may retrieve pointers to other interfaces and accesses basic features of the control via this interface.
IWMPControls Allows an application to access to Windows Media Player controls; for example, it has Play, Stop, and Pause buttons.
IWMPError Provides error information.
IWMPEvents Exposes events that originate from the Windows Media Player control to which an embedding program can respond.
IWMPMedia and IWMPMediaCollection Manages the properties of media items.
IWMPNetwork Sets and retrieves the properties of the network connection used by Windows Media Player.
IWMPPlayer Controls the behavior of the Windows Media Player control user interface.
IWMPPlaylist, IWMPPlaylistArray, and IWMPPlaylistCollection Playlists manupulation.
IWMPSettings Sets or retrieves Windows Media Player settings.

As you can see, this is really only a small part of desktop definitions, but it is still useful anyway.

Creating a First Application

You will start with a simple ATL application, where you easily can create a control container window. The code snippet below uses a standard ATL technique to display the Windows Media Player control:

LRESULT CWMPHost::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam,
                           BOOL& bHandled)
    CComPtr<IAxWinHostWindow>           spHost;
    CComPtr<IConnectionPointContainer>  spConnectionContainer;
    CComWMPEventDispatch                *pEventListener = NULL;
    CComPtr<IWMPEvents>                 spEventListener;
    HRESULT                             hr;
    RECT                                rcClient;

    m_dwAdviseCookie = 0;
    // create window
    m_wndView.Create(m_hWnd, rcClient, NULL,
    if (NULL == m_wndView.m_hWnd)
        goto FAILURE;

    // load OCX in window
    hr = m_wndView.QueryHost(&spHost);
    if (FAILMSG(hr))
        goto FAILURE;

    hr = spHost->CreateControl(CComBSTR(_T("WMPlayer.OCX")),
                               m_wndView, 0);
    if (FAILMSG(hr))
        goto FAILURE;

    hr = m_wndView.QueryControl(&m_spWMPPlayer);
    if (FAILMSG(hr))
        goto FAILURE;

    // start listening to events

    hr = CComWMPEventDispatch::CreateInstance(&pEventListener);
    spEventListener = pEventListener;
    if (FAILMSG(hr))
        goto FAILURE;

    hr = m_spWMPPlayer->QueryInterface(__uuidof(IConnectionPointContainer),
    if (FAILMSG(hr))
        goto FAILURE;

    // See whether OCX supports the IWMPEvents interface
    hr = spConnectionContainer->FindConnectionPoint(__uuidof(IWMPEvents),
    if (FAILMSG(hr))
        goto FAILURE;

    hr = m_spConnectionPoint->Advise(spEventListener, &m_dwAdviseCookie);
    if (FAILMSG(hr))
        goto FAILURE;

    return 0;

    return 0;

All you need to to is to create the control’s window, obtain an IWMPPlayer interface pointer, and sign up to WMP events. ATL is usually the easier way to perform such tasks than MFC; nevertheless, you may use MFC as well. As a result, your application will be able to play Windows Media files such as WMA and WMV.

The WMP control has a number of methods that allow you to control its behavior. For example, you can start playing a media file as follows:

LRESULT CWMPHost::OnFileOpen(WORD wNotifyCode, WORD wID,
                             HWND hWndCtl, BOOL& bHandled)
    CFileOpenDlg dlgOpen;
    HRESULT      hr;

    if (dlgOpen.DoModal(m_hWnd) == IDOK)
        hr = m_spWMPPlayer->put_URL(dlgOpen.m_bstrName);
        if (FAILMSG(hr))
            return 0;
    return 0;

Mobile samples for Windows Media Player 10 provide a full example the of controls’ usage.

More by Author

Must Read