views:

171

answers:

2

Hi, everyone!

I am writing a simple Windows app in c++, that will be able to send commands to windows media player. My problem is that I want my app to move to the previous song in the playlist.

IWMPControls::previous() seems to do the job, but its behavior differs from what is written in msdn. In fact this function rewinds current media to the beginning and then (if current position is less than 2-3 seconds) it switches to the previous song.

I would like to implement two different buttons (please, don't ask me why :)) - one for rewinding to the beginning, and one - to moving to previous song. Is there any easy way to do this through IWMPControls (or any other WMP-related COM interface)?

p.s. I could handle this if I could get the position (index) of the current song in the list. But as far as I read MSDN, it seems to me that there is no easy way to get the current item index from playlist...

A: 

I think, the easiest way to control a WMP application from outside is by sending messages. So, you stick to basic WinAPI and you have to get your WMP window handle.

After you've retrieved it's handle, it's easy to transfer certain commands to it using plain Windows messages.

Basically, you just invoke SendMessage to retrieved earlier HWND wmp_windows_handle. The control messages are generally a WM_COMMAND messages where a wParam specifies what you want your player to do.

For example, Stop command can be transfered if you specify 0x00004979 as your wParam.

Stick to Google or Windows Media Player SDK for more specific information on these command codes and you'll definitely find what you are looking for.

Also to mention, I'm not proficient with that IWMPStuff you described above, so if I were you and I wanted a concrete answer about it, I would probably refer to it's SDK.

Kotti
IWMPCore could have been created without any windows, so there are no handles to receive. Anyway, if I send a "Previous" command somehow, it will do rewind first and then go to previous song, so that is not the solution.
SadSido
You said that you need to determine the index of current song in the list. This can also be done using `SendMessage` technique. Not sure about WMP, but (for example, in Winamp), this is simple and described in SDK.
Kotti
A: 

Well, I think I figured it out. You can force the previous song by 1) first calling IWMPControls::put_currentPosition(0.0), 2) then calling IWMPControls::previous().

There can be some problems, as it seems that some time must pass between 1) and 2). The obvious solution is to use ::PostMessage() inside your program (NOT ::PostMessage to WMP), so you make step 1), then PostMessage and, while processing your message, make step 2).

SadSido