0

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 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 Invokeing 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.

Community
  • 1
  • 1

1 Answers1

1

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)

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • I did not get what does it mean by "If you host player in your windows app..", do you mean I should spawn WMP.exe from within my program? Could you please elaborate more? Like exactly how to host player in my app? –  Aug 17 '14 at 16:46
  • In the COM objects family, there are also "COM Controls" also called "OLE" or "ActiveX" controls. You can only host them 1) visually and 2) using windows. For example, this is how you can host WMP: http://msdn.microsoft.com/en-us/library/windows/desktop/dd563023(v=vs.85).aspx It's impossible to host a WMP control in a Console app w/o a window (by definition). With Media Player, you can use the object (like you do) or the control. That completely changes its behavior. – Simon Mourier Aug 17 '14 at 16:56
  • ok. Thank you sir, i think i got it. So long story short - for WMP Automation hosting ActiveX control is must. –  Aug 17 '14 at 17:20
  • You could make a console app that creates an invisible window and hosts the ActiveX control (whether that is a good idea is another thing) – M.M Aug 19 '14 at 10:25
  • @SimonMourier thank you for your help, I have solved the problem. However, currently I have done it using `MFC and ATL`. I am really willing to learn how to do this without `MFC/ATL`. I have searched a lot, but have not found something which would get me going, SDK samples also are not without these two. I know its going to be hard, but I am willing to take efforts, I cannot sleep in peace. SO by hook or crook I am going to do this, it would be helpful if you may guide.. –  Aug 19 '14 at 18:17
  • @MattMcNabb "console app that creates an invisible window", sorry for my dumb question but I did not get this. Did you mean creating `creatprocess` which hosts the control? Could you please put a little more light on this? –  Aug 19 '14 at 18:20
  • @oh_dear_i_love_coding [see here](http://stackoverflow.com/questions/17965373/create-a-window-in-a-visual-studio-2012-console-application). – M.M Aug 19 '14 at 20:03
  • You can't just create a Window, you need OLE/COM hosting interfaces implemented. You can actually look at ATL's source. It's fully provided with Visual Studio. Anyway, here is a project that has what you need: http://www.codeproject.com/Articles/18417/Use-an-ActiveX-control-in-your-Win-Project-witho this is quite bare and missing some stuff, but it may work with WMP. Now if you got that route with a console, you *will need* a proper message pump... – Simon Mourier Aug 20 '14 at 06:23