如何在 C# 中与 Windows Media Player 交互

发布于 2024-07-04 16:45:51 字数 309 浏览 5 评论 0原文

我正在寻找一种与独立完整版 Windows Media Player 进行交互的方法。
大多数情况下,我需要知道当前播放曲目的路径。

iTunes SDK 使这变得非常简单,但不幸的是,确实没有任何方法可以使用 Windows Media Player 来做到这一点,至少在 .Net(C#) 中没有大量使用 pinvoke,我对此不太满意。

谢谢

只是澄清一下:我不想在我的应用程序中嵌入 Windows Media Player 的新实例,而是控制/读取由用户单独启动的“真实”完整版本的 Windows Media Player

I am looking for a way to interact with a standalone full version of Windows Media Player.
Mostly I need to know the Path of the currently played track.

The iTunes SDK makes this really easy but unfortunately there really isn't any way to do it with Windows Media Player, at least not in .Net(C#) without any heavy use of pinvoke, which I am not really comfortable with.

Thanks

Just to clearify: I don't want to embedded a new instance of Windows Media Player in my app, but instead control/read the "real" full version of Windows Media Player, started seperatly by the user

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

﹏雨一样淡蓝的深情 2024-07-11 16:45:52

我有这个https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbd43d7e-f3a6-4087-be06-df17e76b635d/windows-media-player-remoting-in -c?forum=clr 在我的书签中,但尚未对其进行测试。 只是一个指向正确方向的指针。 它不是官方的,需要进行一些挖掘,但您应该获得一个围绕 Windows Media Player 的相当简单的包装器(它仍然会在幕后使用 PInvoke - 但您不会看到它)。

希望有帮助。

哦,我误会了。 我以为您正在谈论控制当前运行的 Windows Media Player 实例。 如果您自己托管 Windows Media Player,那么 WMPLib 无疑是更好的解决方案。

I had this https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbd43d7e-f3a6-4087-be06-df17e76b635d/windows-media-player-remoting-in-c?forum=clr in my bookmarks but have NOT tested it in anyway. Just a pointer in the right direction. It's nothing official and will require a bit of digging, but you should get a fairly simple wrapper (which will still use PInvoke under the hood - but you won't see it) around Windows Media Player.

Hope that helps.

Oh, I misunderstood. I thought you were talking about controlling the currently running Windows Media Player instance. If you are hosting Windows Media Player yourself then WMPLib is certainly the better solution.

烈酒灼喉 2024-07-11 16:45:52

要远程连接 Windows Media Player,您可以使用 IWMPRemoteMediaServices 接口来控制独立的 Windows Media Player。 您应该能够从 WMP 播放器对象中读取您想要的所有信息,例如标题或文件名。 不幸的是,SDK 中没有包含 C# 示例代码。 您可以从这里获取文件: http://d.hatena.ne.jp/punidama/20080227 查找文件 WmpRemote.zip
最初来自这里: http://blogs.msdn.com/ ericgu/archive/2005/06/22/431783.aspx

然后你必须转换到 WindowsMediaPlayer 对象:
RemotedWindowsMediaPlayer rm = new RemotedWindowsMediaPlayer();
WMPLib.WindowsMediaPlayer myPlayer = this.GetOcx() as WMPLib.WindowsMediaPlayer;

就这样..

For remoting the Windows Media Player, you can use the IWMPRemoteMediaServices interface to control the stand alone Windows Media Player. And you should be able to read all the informations you want like title or filename from your WMP player object. Unfortunately there is no C# smaple code in the SDK included. You can get the files from here: http://d.hatena.ne.jp/punidama/20080227 Look for the file WmpRemote.zip
Originally it's from here: http://blogs.msdn.com/ericgu/archive/2005/06/22/431783.aspx

Then you have to cast to the WindowsMediaPlayer object:
RemotedWindowsMediaPlayer rm = new RemotedWindowsMediaPlayer();
WMPLib.WindowsMediaPlayer myPlayer = this.GetOcx() as WMPLib.WindowsMediaPlayer;

and there you go..

少女情怀诗 2024-07-11 16:45:52

只需添加对 wmp.dll (\windows\system32\wmp.dll) 的引用

using WMPLib;

即可实例化媒体播放器

var Player = new WindowsMediaPlayer();
// Load a playlist or file and then get the title 
var title = Player.controls.currentItem.name;

参见 以编程方式创建 Windows Media Player 控件了解更多信息

Just add a reference to wmp.dll (\windows\system32\wmp.dll)

using WMPLib;

And then you can instantiate a media player

var Player = new WindowsMediaPlayer();
// Load a playlist or file and then get the title 
var title = Player.controls.currentItem.name;

See Creating the Windows Media Player Control Programmatically for more information

姜生凉生 2024-07-11 16:45:52

我见过的有关与 Windows Media Player 交互的最佳信息是这个 文章由 Stephen Toub 撰写。

他列出了播放 dvr-ms 文件的各种不同方法(不过,它们的格式并不重要)。 您可能感兴趣的是关于使用 Media Player ActiveX 控件,您可以通过右键单击并添加 Windows Media Player ActiveX COM 控件来将其添加到 Visual Studio 工具箱。 然后,您可以将播放器嵌入到您的应用程序中,并访问媒体播放器的各种属性,例如网址:

WMPplayer.URL = stringPathToFile;

此解决方案可能不是您想要的,因为它正在启动媒体播放器的新实例(据我所知),但它可能会为您指明正确的方向。

The best info I have seen on interacting with Windows Media Player is this article written by Stephen Toub.

He lists a whole load of different ways to play dvr-ms files (doesn't really matter what format they are for this though). The bit that is possibly of interest to you is about using a Media Player ActiveX Control, which you can add to the visual Studio toolbox by right-clicking and adding the Windows Media Player ActiveX COM Control. You can then embed the player into your app, and access various properties of Media Player, like the url:

WMPplayer.URL = stringPathToFile;

This solution is possibly not what you want because it's starting a new instance of Media Player (as far as I know), however it might point you in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文