如何让 Windows Media Player 转到播放列表中的上一首歌曲?
我正在用 C++ 编写一个简单的 Windows 应用程序,它将能够向 Windows 媒体播放器发送命令。我的问题是我希望我的应用程序移至播放列表中的上一首歌曲。
IWMPControls::previous() 似乎可以完成这项工作,但其行为与 msdn 中编写的不同。事实上,此功能会将当前媒体倒回到开头,然后(如果当前位置小于 2-3 秒)切换到上一首歌曲。
我想实现两个不同的按钮(请不要问我为什么:)) - 一个用于倒带到开头,一个 - 移动到上一首歌曲。有没有简单的方法可以通过 IWMPControls(或任何其他与 WMP 相关的 COM 接口)来做到这一点?
ps 如果我能获取当前歌曲在列表中的位置(索引),我就可以处理这个问题。但据我阅读 MSDN,在我看来,没有简单的方法可以从播放列表中获取当前项目索引......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,从外部控制 WMP 应用程序的最简单方法是发送消息。因此,您坚持使用基本的 WinAPI,并且必须获取 WMP 窗口句柄。
检索到它的句柄后,可以使用纯 Windows 消息轻松地将某些命令传输给它。
基本上,您只需调用
SendMessage
来检索之前的HWND wmp_windows_handle
。控制消息通常是WM_COMMAND
消息,其中wParam
指定您希望播放器执行的操作。例如,如果您指定
0x00004979
作为wParam
,则可以传输Stop
命令。请继续使用 Google 或 Windows Media Player SDK 来获取有关这些命令代码的更多具体信息,您一定会找到您想要的内容。
还要提一下,我不熟悉你上面描述的 IWMPStuff,所以如果我是你并且我想要一个具体的答案,我可能会参考它的 SDK。
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 earlierHWND wmp_windows_handle
. The control messages are generally aWM_COMMAND
messages where awParam
specifies what you want your player to do.For example,
Stop
command can be transfered if you specify0x00004979
as yourwParam
.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.
好吧,我想我明白了。您可以通过以下方式强制播放上一首歌曲:1) 首先调用 IWMPControls::put_currentPosition(0.0),2) 然后调用 IWMPControls::previous()。
可能会出现一些问题,因为 1) 和 2) 之间似乎必须经过一段时间。显而易见的解决方案是在程序中使用 ::PostMessage() (而不是 ::PostMessage 到 WMP),因此您执行步骤 1),然后执行 PostMessage,并在处理消息时执行步骤 2)。
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).