Click here to get back home

creating WMP embedded control

 HomeNewsGroups | Search | About
 microsoft.public.smartphone.developer    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
creating WMP embedded control Tom Moon 04-28-2006
Get Chitika Premium
Posted by Tom Moon on April 28, 2006, 7:43 pm
Please log in for more thread options
> 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


Posted by Chaser7016 on April 30, 2006, 9:30 pm
Please log in for more thread options
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" wrote:

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

Posted by Tom Moon on May 1, 2006, 3:58 pm
Please log in for more thread options
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


Posted by bojan.konic on May 1, 2006, 5:32 pm
Please log in for more thread options
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;
}


Similar ThreadsPosted
creating WMP embedded control (continued) June 20, 2006, 7:17 pm
Embedded VC++ License April 15, 2006, 4:09 am
Can we test embedded app ? April 24, 2008, 5:00 am
Get antenna signal in embedded c++ April 16, 2006, 5:52 am
how to access call history with embedded vc++ January 25, 2006, 3:31 pm
Installing embedded Visual C++ 3.0 on Windows Visa machine? April 18, 2007, 1:53 pm
Embedded Live Messenger Problem to Mobile device April 13, 2008, 5:26 pm
Problem with creating dll November 16, 2006, 6:51 am
Creating new profile April 3, 2007, 4:25 am
Mobile Application with ActiveX support fails for embedded system October 10, 2006, 12:10 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap