I have been trying to achieve Media Player Automation. Have almost tried every possible way I was aware of, but without any success. Few of the tries are listed below.
CAN-NOT create LOCAL_SERVER, no matter what I try. for
CLSCTX_LOCAL_SERVER
I always getclass not registered error
.Started with console application, converted it to Window Application which has Message Pump as suggested here, but still could not play WMP.
Anyway, I went ahead with
IWMPPlayer4
, on which openPlayer() method indeed works, opens WMP and starts playing clip. But any other messages are not reaching WMP. For e.g.IWMPSettings *pMediaPlayerSettings = NULL; hr = pMediaPlayer4->get_settings(&pMediaPlayerSettings); if(FAILED(hr)) { std::cout << "ERR - Could not get WMPSettings Interface Pointer" << std::endl; ReleaseInterfaces((IUnknown**)&pMediaPlayer4); return 0; } std::cout << "Got settings.. lets change volume" << std::endl; int cnt = 10; while(cnt > 1) { long vol = -1.0; Sleep(2000); hr = pMediaPlayerSettings->get_volume(&vol); if(FAILED(hr)) { std::cout << "ERR - Could not change the volume" << std::endl; } std::cout << "Currently volume is: " << vol << std::endl; hr = pMediaPlayerSettings->put_volume(cnt*cnt); cnt--; } ReleaseInterfaces((IUnknown**) &pMediaPlayerSettings);
This code CHANGES the volume, but somehow that effect is not there in the clip which is being played.
Then I thought may be
Invoke
ing will send the messages to WMP running current clip. Tried that code as well but to no avail.
So all I am asking for is -- What I am trying, IS IT POSSIBLE AT ALL?
Raw-COM code to control media player? Any pointers, examples, code snippets are more than welcome. I have a wrong feeling that I have surfed entire cyber-world regarding this issue. Please prove me wrong.
PS: I do not want to do ActiveX or MFC coding.