简体   繁体   English

C ++-完全没有ActiveX或MFC的Windows Media Player自动化是否可能?

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

I have been trying to achieve Media Player Automation. 我一直在尝试实现Media Player自动化。 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. 无论我如何尝试,都无法创建LOCAL_SERVER。 for CLSCTX_LOCAL_SERVER I always get class not registered error . 对于CLSCTX_LOCAL_SERVER我总是收到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. 从控制台应用程序开始,按此处建议将其转换为具有Message Pump的 Window Application,但仍无法播放WMP。

  • Anyway, I went ahead with IWMPPlayer4 , on which openPlayer() method indeed works, opens WMP and starts playing clip. 无论如何,我就做了IWMPPlayer4 ,其上openPlayer()方法确实有效,打开WMP并开始播放剪辑。 But any other messages are not reaching WMP. 但是其他任何消息均未到达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. 然后我想可能是Invoke ing将消息发送到运行当前剪辑的WMP。 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? Raw-COM代码来控制媒体播放器? 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. PS:我不想做ActiveX或MFC编码。

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. 您可以在Windows应用程序中尝试相同的操作,其行为也相同。

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. 这是因为在这种情况下,播放器没有作为控件托管(作为OLE控件,在Window中),因此不被支持。 If you host it in a Windows app or in Internet Explorer, you will see it works fine. 如果将其托管在Windows应用程序或Internet Explorer中,则可以正常运行。

In this configuration, if you want to control the volume, you should use the volume audio APIs (and specifically ISimpleAudioVolume) 在此配置中,如果要控制音量,则应使用音量音频API (特别是ISimpleAudioVolume)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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