开发者

How to make windows media player go to previous song in playlist?

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 w开发者_StackOverflow社区ritten 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...


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜