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
If this is the code, where would I add the socket information for my online
radio station?
Cheers, Chaser
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
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;
}