Re: WMP doesn't play a media on a thread
- From: sisimma <sisimma@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 May 2008 09:32:01 -0700
Thank you for your anwser.
Actually, my code has been running as you told.
The problem doesn't seem to relate timing. My code gives enough time for WMP
to run.
Please give me another comment after review my code snippet in more detail
below
HRESULT MAWMPControl()
{
IWMPPlayer4 *pWP;
IWMPSettings *pWPSet;
IWMPControls *pWPCtrl;
HRESULT hr = S_OK;
CComBSTR bstrVersionInfo;
BSTR bstr_path, bstr_playmode;
hr = CoCreateInstance( __uuidof(WindowsMediaPlayer), NULL,
CLSCTX_INPROC_SERVER, __uuidof (IWMPPlayer4),(void **)&pWP);
hr = pWP->QueryInterface(__uuidof(IWMPSettings), (void **)&pWPSet);
hr = pWP->QueryInterface(__uuidof(IWMPControls), (void **)&pWPCtrl);
bstr_path = SysAllocString(L"\\Program Files\\CMA16\\Beep.mp3");
bstr_playmode=SysAllocString(L"loop");
hr = pWP->openPlayer(mybstr);
hr = pWPSet->setMode(bstr_playmode,TRUE);
hr = pWPSet->put_autoStart(TRUE);
//hr = pWPSet->put_playCount(100);
hr = pWPSet->put_volume(100);
hr = pWP->put_URL(bstr_path);
return hr;
}
thread1()
{
MAWMPControl();
while(1)
{
somefunction();
}
}
Main()
{
CoInitializeEx(NULL,COINIT_MULTITHREADED);
MAWMPControl();
createthread(thread1);
while(1)
{
mainfunction();
}
CoUninitialize();
}
"Alessandro Angeli" wrote:
From: "sisimma".
Is there anyone who can tell the difference between a[...]
class, which maybe it runs on a process, and a thread,
which is created from the class?
You are comparing apple and oranges: a thread is a sequence
of operations executed at runtime while a class is just a
way to organize your source code for the compiler. All code
is executed on a thread, whether created by you or somebody
else, and regardless of where you put it in your source
files.
The problem here is that you seem to not be waiting for WMP
to even start playing, let alone finish playing, before
uninitializing COM and destroying the thread, without even
properly releasing WMP. You are most likely causing a
resource leak and you are lucky you are not causing a crash.
Most likely it works when you call the function from your
main thread simply because the main thread will keep running
giving WMP time to perform its task.
You must wait for WMP to finish playing, then you can
release it, uninitialize COM and let the thread exit. It
would be a good idea to also dispatch messages on this
thread while you wait for WMP to finish.
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm
- Follow-Ups:
- Re: WMP doesn't play a media on a thread
- From: Alessandro Angeli
- Re: WMP doesn't play a media on a thread
- References:
- WMP doesn't play a media on a thread
- From: sisimma
- Re: WMP doesn't play a media on a thread
- From: Alessandro Angeli
- WMP doesn't play a media on a thread
- Prev by Date: Re: Read wmcap.exe output in Java.
- Next by Date: Re: WMP doesn't play a media on a thread
- Previous by thread: Re: WMP doesn't play a media on a thread
- Next by thread: Re: WMP doesn't play a media on a thread
- Index(es):
Relevant Pages
|
Loading