Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

creating WMP embedded control

30 views
Skip to first unread message

Tom Moon

unread,
Apr 28, 2006, 7:43:55 PM4/28/06
to
> Hi Tom,
> I'm trying desperately to find a way to
> play a mp3 in my Winmobile 5.0 Application without opening a WMP Window.
> I read most of your posts in google groups and it seems to me that you are the only one
> who has been at least almost succesful with this task.
> Did you have any newer success with it recently?
> Thanks for any help in advance.
> Sincerely,
> Bojan Konic,
> Student at ETH Zuerich, Switzerland

Yes, I was able to play mp3s with WinMobile5.0 WMP10.

Start from here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/usingthewindowsmediaplayercontrolinaconsoleapplica.asp


<code>
CComBSTR bstrVersionInfo; // WMP version string.
// COM smart pointers to WMP interfaces
CComPtr<IWMPPlayer> spPlayer;
CComPtr<IWMPPlayer3> spPlayer3 = NULL;
CComPtr<IWMPCore> spWMPCore = NULL;
CComPtr<IWMPCore3> spWMPCore3 = NULL;
CComPtr<IWMPControls> spControls = NULL;
CComPtr<IWMPSettings> spSettings = NULL;
CComPtr<IWMPSettings2> spSettings2 = NULL;
CComPtr<IWMPPlaylist> spPlaylist = NULL;

HRESULT hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
if(S_OK != hr){
return FALSE;
}

// this is the most important interface
hr = spPlayer.CoCreateInstance(
__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER
);

// set the other derived and retrieved interface pointers
hr = spPlayer->QueryInterface(&spWMPCore);
hr = spWMPCore->QueryInterface(&spWMPCore3);
hr = spPlayer->QueryInterface(&spPlayer3);
hr = spPlayer->get_settings(&spSettings);
hr = spPlayer->get_controls(&spControls);
hr = (spPlayer)->get_currentPlaylist(&spPlaylist);

// print the version info - sanity check;
hr = (MMSS_WMP::spPlayer)->get_versionInfo(&bstrVersionInfo);
wprintf(
L"Windows Media Player Version '%s'\r\n",
bstrVersionInfo.m_str
);

{
// local smartpointers are cool
CComPtr<IWMPMedia> spMedia;
// create a new media with
// our passed URL (i.e. file path)
hr = spWMPCore3->newMedia(
(BSTR)L"//foo.mp3", &spMedia
);
hr = spPlaylist->appendItem(spMedia);
}
hr = spControls->play();
</code>

And of course, here's the WMP COM API reference.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/interfaces.asp

I ran into a bug (of very many bugs in Mobile WMP) wherein some mp3s
just wouldn't play. It most likely had something to do with their
encoding. Try mp3s created by different encoders if the above sample
doesn't work.
Also, you should check all returned HRESULTs. I removed that code for
clarity.

-J Tom Moon
Qualnetics

Chaser7016

unread,
Apr 30, 2006, 9:30:01 PM4/30/06
to
Can this code be placed into a html page and visitors on Windows Smartphones
will then see the embedded WM Player? I want to have the ability through my
Windows Smartphone to go to my website via the phone, see the embedded WM
Player and then tune into my online radio station.

If this is the code, where would I add the socket information for my online
radio station?

Cheers, Chaser

Tom Moon

unread,
May 1, 2006, 3:58:08 PM5/1/06
to
Chaser,
That is a really fun idea! And I have no idea if it would work!
I'm not familiar with world of web site scripting.

I would *guess* that maybe you can do something with VB Script that
opens a WMP COM interface and go from there.
If you get something working you should post a short How-To here and
link to your website.

-J Tom Moon
Qualnetics

bojan...@gmail.com

unread,
May 1, 2006, 5:32:37 PM5/1/06
to
Tom,

first, thanks a lot for your answer.
It helped me a lot, although I'm still struggling with the Interface:
the following line returns a S_FALSE for hr and no sound is played.

hr = spControls->play();

But if I get the ErrorItem from the Media, the description just says,
that the operation has been successfull.

-All other calls return hr = S_True.
-The messagebox containing the version of WMP appears as it's supposed
to.
-I don't get any access violations or other errors, the code just runs
through smoothly.

Do you have any clue, why the call to play() fails?

Below my code (it's basically yours, I just added some lines to get the
errors)

(Besides: the calls to QueryInterface needed a second argument, yours
just had one.
Do you have another version of the SDK or something?)


Thanks in advance,

Bojan

----------------
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "atlbase.h"
#include "atlwin.h"
#include "wmp.h"
#include <atlcom.h>
#include "wmpids.h"

//IWMPSyncDevice **m_ppWMPDevices;
//int m_cDevices; // Count of devices.

int _tmain(int argc, _TCHAR* argv[])
{
VARIANT_BOOL ready_to_play;
VARIANT_BOOL *ptr_ready_to_play;
ready_to_play = VARIANT_FALSE;


CComBSTR bstrVersionInfo; // WMP version string.
// COM smart pointers to WMP interfaces
CComPtr<IWMPPlayer> spPlayer;
CComPtr<IWMPPlayer3> spPlayer3 = NULL;
CComPtr<IWMPCore> spWMPCore = NULL;
CComPtr<IWMPCore3> spWMPCore3 = NULL;
CComPtr<IWMPControls> spControls = NULL;
CComPtr<IWMPSettings> spSettings = NULL;
CComPtr<IWMPSettings2> spSettings2 = NULL;
CComPtr<IWMPPlaylist> spPlaylist = NULL;

HRESULT hr = CoInitializeEx(NULL,COINIT_MULTITHREADED);
if (!SUCCEEDED(hr)) {
return FALSE;
}


if(S_OK != hr){
return FALSE;
}

// this is the most important interface
hr = spPlayer.CoCreateInstance(
__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER
);

// set the other derived and retrieved interface pointers
hr =

spPlayer->QueryInterface(__uuidof(spWMPCore),(void**)&spWMPCore);
hr = spWMPCore->QueryInterface(__uuidof(spWMPCore3),(void **)
&spWMPCore3);
hr =
spPlayer->QueryInterface(__uuidof(spPlayer3),(void**)&spPlayer3);


hr = spPlayer->get_settings(&spSettings);
hr = spPlayer->get_controls(&spControls);

hr = spPlayer->get_currentPlaylist(&spPlaylist);

// print the version info on a message box - sanity check;
hr = spPlayer->get_versionInfo(&bstrVersionInfo);


wprintf(
L"Windows Media Player Version '%s'\r\n",
bstrVersionInfo.m_str
);

COLE2T pStr(bstrVersionInfo);
MessageBox( NULL, (LPCWSTR)pStr, _T("Windows Media Player
Version"), MB_OK );
//--> works always.

//Init new Media... (and Media2 for Error information)
CComPtr<IWMPMedia> spMedia = NULL;
CComPtr<IWMPMedia2> spMedia2 = NULL;

// create a new media with

//start with a preinstalled WAV File
//to avoid any errors with missing codecs or wrong pathes.
hr = spWMPCore3->newMedia(
(BSTR)L"\\Windows\\Dogbark.wav", &spMedia
);


//get error item from Core.
CComPtr<IWMPError> core_error;
CComPtr<IWMPErrorItem> core_error_item;
BSTR core_err_description;
hr = spWMPCore3->get_error(&core_error);
long num_errors;
//See if there are any errors.
hr = core_error->get_errorCount(&num_errors);
//-->num_errors seems to be always 0.
if (num_errors > 0) {
//get first error
hr = core_error->get_item (0, &core_error_item);
hr= core_error_item->get_errorDescription
(&core_err_description);
}

//Connect spMedia to spMedia2 ,so we can get error information
about media.
hr = spMedia->QueryInterface(__uuidof(spMedia2),(void**)&spMedia2);
CComPtr<IWMPErrorItem> media_error;
hr = spMedia2->get_error(&media_error);

BSTR error_description;
hr = media_error->get_errorDescription ( &error_description);

//Append new media to playlist
hr = spPlaylist->appendItem(spMedia);

//check if we are ready to play file.
hr = spControls->get_isAvailable ((BSTR)L"play", &ready_to_play);
//-->ready_to_play returns -1 which is VARIANT_TRUE.

//Let's see if the media points to the right file...
BSTR source_url;
hr = spMedia->get_sourceURL ( &source_url);
//-->the Media has the right URL (\windows\Dogbark.wav)

//Start playing...
hr = spControls->play();
//-->hr returns S_FALSE, no sound playing


//See if we ca get information about the error from the player
//get error item from Player.
CComPtr<IWMPError> player_error;
CComPtr<IWMPErrorItem> player_error_item; //not used yet
BSTR player_err_description;
hr = spPlayer->get_error(&player_error);
long player_num_errors;
//See if there are any errors.
hr = player_error->get_errorCount(&player_num_errors);
//-->player_num_errors is 0 as well.


//See if we can get information about the error from media
CComPtr<IWMPErrorItem> media_error2;
hr = spMedia2->get_error(&media_error2);
hr = media_error2->get_errorDescription ( &error_description);
//-->error_description says that operation was successful (no
error)

return 0;
}

0 new messages