Re: WMP doesn't play a media on a thread



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



.



Relevant Pages

  • Re: Now Playing no longer saves on close?
    ... Then it stops (not during a song, ... I click on it and WMP11 starts playing it's ... song played...or even the radio station I was playing...if I was doing ... cause I have WMP minimized as a toolbar. ...
    (microsoft.public.windowsmedia.player)
  • Re: WMP doesnt play a media on a thread
    ... 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, ... resource leak and you are lucky you are not causing a crash. ...
    (microsoft.public.windowsmedia.sdk)
  • Re: continue playback after sleep
    ... the song it's playing, that bar is simply missing!?). ... Please do help me with this very irritating problem, or else WMP ... position from when i put the computer to sleep. ...
    (microsoft.public.windowsmedia.player)
  • Re: Using an External Hard Drive
    ... can only reveal on Now Playing the files in one of the folders on E: ... I've been trying for some time to play them using Windows Media Player, ... No Tom E. WMP is open on the Library tab with Playlists and Library ...
    (microsoft.public.windowsmedia.player)
  • Re: Why am i banned ?
    ... WMP 11 NOW PLAYING - Renaissance The Classics Part 2 ...
    (uk.games.video.xbox)

Loading