Y
Yarek
Hi. I've posted before asking about IWMPPlayer. I'm writing a small,
multithreaded app that has to run on XP and Vista; it uses WMP Console
interface to play local files (files and cd's). The code initializes the
IWMPPlayer in one thread and another thread is invoked to play audio.
The issue is the following. The code works fine on Vista; I can load and
play files number of times. However, on XP, I can load and play a file only
once; on a second attempt I can load it but no longer play it. I can play the
same file loaded previously, but if I try to change the active item in a
playlist to a new file, the program crashes. Please notice; I've tested this
XP Issue on XP Pro with WMP 11 and xp64 with WMP 10. The problem occurs only
on XP Pro with WMP11. Once I upgraded xp64 to WMP11 the problem begun
appearing as well. Here's a code snippet. Anyone familiar with this issue and
perhaps knows how to resolve it? Any input greatly appreciated.
I initialize object in the init function; then I run the wmp object in a
separate thread.
initialization:
hr = this->m_spWMPlayer.CoCreateInstance(__uuidof(WindowsMediaPlayer), 0,
CLSCTX_INPROC_SERVER);
if( FAILED(hr) )
{
this->_pLogger->error(this->_pLogger->name() + "Failed to Init
m_spWMPPlayer");
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->QueryInterface(&m_spWMPCore);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPCore->QueryInterface(&m_spWMPCore3);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->QueryInterface(&m_spPlayer3);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->get_settings(&m_spWMPSettings);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->get_controls(&m_spWMPControls);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->get_currentPlaylist(&m_spWMPlaylist);
}
stm:layer::CComWMPEventDispatch *pEventListener = NULL;
// start listening to events
if (SUCCEEDED(hr))
{
hr =
CComObject<stm:layer::CWMPEventDispatch>::CreateInstance(&pEventListener);
m_spEventListener = pEventListener;
}
if (SUCCEEDED(hr))
{
hr = m_spWMPlayer->QueryInterface(&m_spConnectionContainer);
}
// See if OCX supports the IWMPEvents interface
hr = m_spConnectionContainer->FindConnectionPoint(__uuidof(IWMPEvents),
&m_spConnectionPoint);
if (FAILED(hr))
{
// If not, try the _WMPOCXEvents interface, which will use IDispatch
hr =
m_spConnectionContainer->FindConnectionPoint(__uuidof(_WMPOCXEvents),
&m_spConnectionPoint);
if (FAILED(hr))
return -1;
}
hr = m_spConnectionPoint->Advise(m_spEventListener, &m_dwAdviseCookie);
if (FAILED(hr))
return -1;
// INVOCATION
lBstrPathName = (BSTR)this->m_wStrToPlayPath.c_str();
if(m_spWMPMedia){
m_spWMPMedia.Release();
}
if(m_spWMPSettings)
hr = m_spWMPSettings->put_autoStart(FALSE);
if(SUCCEEDED(hr))
{
hr = m_spWMPCore3->newMedia(lBstrPathName, &m_spWMPMedia);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlaylist->appendItem(m_spWMPMedia);
}
// THIS CRASHES ON XP ON A SECOND ATTEMPT TO PLAY A FILE
if(SUCCEEDED(hr))
{
hr = m_spWMPControls->put_currentItem(m_spWMPMedia);
}
// END THIS CRASHES
if (PeekMessage (&lMsg, NULL, 0, 0, PM_REMOVE))
{
std::cerr << "lMsg: " << lMsg.message << " " << std::endl;
TranslateMessage (&lMsg) ;
DispatchMessage (&lMsg) ;
} // end if peekmsg
multithreaded app that has to run on XP and Vista; it uses WMP Console
interface to play local files (files and cd's). The code initializes the
IWMPPlayer in one thread and another thread is invoked to play audio.
The issue is the following. The code works fine on Vista; I can load and
play files number of times. However, on XP, I can load and play a file only
once; on a second attempt I can load it but no longer play it. I can play the
same file loaded previously, but if I try to change the active item in a
playlist to a new file, the program crashes. Please notice; I've tested this
XP Issue on XP Pro with WMP 11 and xp64 with WMP 10. The problem occurs only
on XP Pro with WMP11. Once I upgraded xp64 to WMP11 the problem begun
appearing as well. Here's a code snippet. Anyone familiar with this issue and
perhaps knows how to resolve it? Any input greatly appreciated.
I initialize object in the init function; then I run the wmp object in a
separate thread.
initialization:
hr = this->m_spWMPlayer.CoCreateInstance(__uuidof(WindowsMediaPlayer), 0,
CLSCTX_INPROC_SERVER);
if( FAILED(hr) )
{
this->_pLogger->error(this->_pLogger->name() + "Failed to Init
m_spWMPPlayer");
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->QueryInterface(&m_spWMPCore);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPCore->QueryInterface(&m_spWMPCore3);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->QueryInterface(&m_spPlayer3);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->get_settings(&m_spWMPSettings);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->get_controls(&m_spWMPControls);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlayer->get_currentPlaylist(&m_spWMPlaylist);
}
stm:layer::CComWMPEventDispatch *pEventListener = NULL;
// start listening to events
if (SUCCEEDED(hr))
{
hr =
CComObject<stm:layer::CWMPEventDispatch>::CreateInstance(&pEventListener);
m_spEventListener = pEventListener;
}
if (SUCCEEDED(hr))
{
hr = m_spWMPlayer->QueryInterface(&m_spConnectionContainer);
}
// See if OCX supports the IWMPEvents interface
hr = m_spConnectionContainer->FindConnectionPoint(__uuidof(IWMPEvents),
&m_spConnectionPoint);
if (FAILED(hr))
{
// If not, try the _WMPOCXEvents interface, which will use IDispatch
hr =
m_spConnectionContainer->FindConnectionPoint(__uuidof(_WMPOCXEvents),
&m_spConnectionPoint);
if (FAILED(hr))
return -1;
}
hr = m_spConnectionPoint->Advise(m_spEventListener, &m_dwAdviseCookie);
if (FAILED(hr))
return -1;
// INVOCATION
lBstrPathName = (BSTR)this->m_wStrToPlayPath.c_str();
if(m_spWMPMedia){
m_spWMPMedia.Release();
}
if(m_spWMPSettings)
hr = m_spWMPSettings->put_autoStart(FALSE);
if(SUCCEEDED(hr))
{
hr = m_spWMPCore3->newMedia(lBstrPathName, &m_spWMPMedia);
}
if(SUCCEEDED(hr))
{
hr = m_spWMPlaylist->appendItem(m_spWMPMedia);
}
// THIS CRASHES ON XP ON A SECOND ATTEMPT TO PLAY A FILE
if(SUCCEEDED(hr))
{
hr = m_spWMPControls->put_currentItem(m_spWMPMedia);
}
// END THIS CRASHES
if (PeekMessage (&lMsg, NULL, 0, 0, PM_REMOVE))
{
std::cerr << "lMsg: " << lMsg.message << " " << std::endl;
TranslateMessage (&lMsg) ;
DispatchMessage (&lMsg) ;
} // end if peekmsg