Media Player-based multimedia development in WinCE

Source: Internet
Author: User

In the past 10 years, mobile technology has made incredible progress and achievements. Mobile devices using Windows CE have become more flexible and convenient in terms of application and programming. Windows Media Player 10 mobile is added to the latest Windows CE device. It provides the same powerful features as WMP controls on PCs. You can add multimedia capabilities for your mobile devices, including playing videos, audio files, and displaying images. You can find the available sdks, resources, and other related information in the paragraphs attached to the document.
Below we will briefly introduce some implementation technologies of WMP.

  Statement

The wmp sdk provides many interfaces, but not all of them can be applied to the Windows Mobile platform. The following lists available information and explains it:

Interface Description
Iwmpcore The Root Interface of the WMP object model. You can obtain pointers from other interfaces and use them to access the basic features of other spaces.
Iwmpcontrols Allows an application to access the Windows Media Player control, such as its playback, stop, and pause buttons.
Iwmperror Provides error information.
Iwmpevents Events generated by the Windows Media Player control are provided to an embedded program that can be fed back.
Iwmpmedia, iwmpmediacollection Manage attributes of a media item.
Iwmpnetwork Set and obtain the network connection used by Windows Media Player
Iwmpplayer Controls the behavior of user interfaces in the Windows Media Player space.

Iwmpplaylist,
Iwmpplaylistarray,
Iwmpplaylistcollection

Playlist operation.
Iwmpsettings Set or obtain the settings of Windows Media Player.

  Create the first application

The following is a simple ATL application. You will create a space container window. The following code snippet uses a standard ATL technology to demonstrate the Windows Media Player control:

Lresult cwmphost: oncreate (uint umsg, wparam, lparam, bool & bhandled)
{
Atlaxwininit ();
Ccomptr <iaxwinhostwindow> sphost;
Ccomptr <iconnectionpointcontainer> spconnectioncontainer;
Ccomwmpeventdispatch * peventlistener = NULL;
Ccomptr <iwmpevents> speventlistener;
Hresult hr;
Rect rcclient;
M_dwadvisecookie = 0;
...
// Create a window
Getclientrect (& rcclient );
M_wndview.create (m_hwnd, rcclient, null, ws_child | ws_visible | ws_clipchildren | ws_clipsiblings );
If (null = m_wndview.m_hwnd) goto failure;
// Load ocx in the 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 for events
HR = ccomwmpeventdispatch: createinstance (& peventlistener );
Speventlistener = peventlistener;
If (failmsg (HR) goto failure;
HR = m_spwmpplayer-> QueryInterface (_ uuidof (iconnectionpointcontainer), (void **) & spconnectioncontainer); If (failmsg (HR) goto failure;
// Check whether OCX supports the iwmpevents Interface
HR = spconnectioncontainer-> findconnectionpoint (_ uuidof (iwmpevents), & m_spconnectionpoint );
If (failmsg (HR) goto failure;
HR = m_spconnectionpoint-> advise (speventlistener, & m_dwadvisecookie );
If (failmsg (HR) goto failure;
Return 0; Failure: postquitmessage (0 );
Return 0;
}

All you have to do is create a control window that contains an iwmpplayer interface pointer and responds to WMP events. ATL can be used to complete these tasks in a simpler way than MFC. Of course, you can also use MFC. Your program can now play Windows Media files, such as WMA and WMV.

The WMP control also allows programmers to control its behavior. For example, you can start playing a media file like this:

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;
}

The mobile example of Windows Mobile Player 10 provides a series of control usage examples.InWebUse WMP ocx in applications

When using a Web browser, it is easier to apply WMP programming (this is an example in the SDK ):

<HTML>
<Head>
</Head>
<Body>
<Object ID = wmpocx width = 200 Height = 150 classid = "CLSID: 6bf52a52-394a-11d3-b153-00c04f79faa6" type = "application/X-oleobject" viewastext>
<Param name = "uimode" value = "NONE">
</Object> <br>
<Script for = "wmpocx" event = "playstatechange (newstate)" Language = "jscript"> clipplaystate (newstate );
</SCRIPT>
<Script for = "wmpocx" event = "error ()" Language = "jscript"> stopplayer (); </SCRIPT>
<P>
<A href = # onclick = 'playclip ("/storage card/webapp/Glass. wmv", imgvideoplay, true) '>

</A>
Video <br>
<A href = # onclick = 'playclip ("/storage card/webapp/jeanne.wma", imgaudioplay, false) '>

</A> audio <br>
Play state sequence <br>
<Input type = "text" id = "playstatesequence" width = 30>
<Script language = "jscript">
<! -- Var currentplayimage = NULL;
VaR bvideo = NULL;
VaR bwasbuffering = false;
Function stopplayer ()
{
Wmpocx. Controls. Stop ();
Wmpocx. Close ();
If (currentplayimage! = NULL)
{
Currentplayimage. src = "bt_play.gif ";
}
Bwasbufferring = false;
}
Function clipplaystate (newstate)
{
Playstatesequence. value = playstatesequence. Value + newstate + "";
Switch (newstate ){
Case 1:
// Stopped
If (bwasbuffering)
{
Bwasbufferring = false;
If (currentplayimage! = NULL)
{
Currentplayimage. src = "bt_play.gif ";
}
}
Break;
Case 6:
// Buffering
Bwasbufferring = true;
If (currentplayimage! = NULL)
{
Currentplayimage. src = "bt_load.gif ";
}
Break;
Case 9:
// Transitioning
Case 11:
// Reconnecting
Bwasbufferring = false;
Break;
Case 3:
// Playing
If (bwasbufferring)
{
If (currentplayimage! = NULL)
{
Currentplayimage. src = "bt_stop.gif ";
}
If (bvideo)
{
Wmpocx. fullscreen = true;
}
}
Break;
Default:
}
}
Function playclip (URL, IMG, video)
{
If (wmpocx. playstate = 3 & bvideo! = NULL & bvideo! = Video)
{
Return;
}
Bvideo = video;
Currentplayimage = IMG;
If (wmpocx. playstate = 3)
{
Stopplayer ();
}
Else
{
Playstatesequence. value = "";
If (currentplayimage! = NULL)
{
Currentplayimage. src = "bt_load.gif ";
}
Wmpocx. url = URL;
}
}
-->
</SCRIPT>
</Body>
</Html>

Use the old WMP Control

If the handheld device you are using does not have wmp10. You can still use wmp ocx version 8 to program your Pocket PC. Although it provides fewer features, it can basically meet your needs. I created a simple project to demonstrate how it works in the MFC environment. The following code snippet proves that it is as simple as the ATL method:

Bool cwmp8sampledlg: oninitdialog ()
{
Cdialog: oninitdialog ();
// Set the icon for this dialog. The framework does this
// Automatically when the application's main window is not
// A dialog
Seticon (m_hicon, true );
// Set big icon
Seticon (m_hicon, false );
// Set small icon
Centerwindow (getshorttopwindow ());
// Center to the HPC Screen
Crect rect;
M_panel.getclientrect (& rect );
If (m_playerwnd.createcontrol (_ uuidof (WMP), L "", ws_visible | ws_child, rect, & m_panel, afx_idw_pane_first ))
{
Lpunknown lpunk = m_playerwnd.getcontrolunknown ();
Hresult hR = lpunk-> QueryInterface (_ uuidof (iwmp), (void **) & m_spwmpplayer );
}
Else
{
Afxmessagebox (L "failed to create WMP control ");
: Postquitmessage (0 );
Return 0;
}
If (m_spwmpplayer)
{
M_wmpevents.m_pmaindlg = (cwmp8sampledlg *) This;
Ccomptr <iconnectionpointcontainer> spconnectioncontainer;
Hresult hR = m_spwmpplayer-> QueryInterface (iid_iconnectionpointcontainer, (void **) & spconnectioncontainer );
If (succeeded (HR ))
{
HR = spconnectioncontainer-> findconnectionpoint (_ uuidof (_ iwmpevents), & m_spconnectionpoint );
}
If (succeeded (HR) {hR = m_spconnectionpoint-> advise (idispatch *) & m_wmpevents, & m_dwadvisecookie );
}
Else
{
Afxmessagebox (L "failed to get WMP control events ");
: Postquitmessage (0 );
Return 0;
}
If (failed (setupwmp ()))
{
Afxmessagebox (L "failed to setup WMP control ");
: Postquitmessage (0 );
Return 0;
}
}
M_spwmpplayer-> stop ();
Return true;
// Return true unless you set the focus to
// Control
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.