简体   繁体   中英

C++ - Is Windows Media Player Automation without ActiveX or MFC possible at all?

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 get class 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 eg

     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.

This problem has nothing to do with the fact your application is a Console application. The message pump is out of the subject here. You can try the same with a Windows app and it will behave the same.

It's because in this case, the player is not hosted as a control (as an OLE control, in a Window) so it's just not supported. If you host it in a Windows app or in Internet Explorer, you will see it works fine.

In this configuration, if you want to control the volume, you should use the volume audio APIs (and specifically ISimpleAudioVolume)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM