0

我正在尝试创建一个小型应用程序,通知用户当前在 Windows Media Player 上播放的歌曲的路径。

所以我四处搜索并发现了一个很好的代码:

WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
// Get an interface to the first media item in the library. 
WMPLib.IWMPMedia3 firstMedia = (WMPLib.IWMPMedia3)player.mediaCollection.getAll().get_Item(0);

// Make the retrieved media item the current media item.
player.currentMedia = firstMedia;

// Display the name of the current media item.
currentMediaLabel.Text = ("Found first media item. Name = " + player.currentMedia.name);

但问题是这段代码实际上是获取列表中的第一首歌曲而不是获取当前歌曲,我尝试更改方法但没有好处:(我希望你能帮助我。

4

2 回答 2

2

你已经在player.currentMedia.

WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();

// start the player
...

if(player.currentMedia != null)
{
    // Display the name of the current media item.
    currentMediaLabel.Text = ("Found first media item. Name = "
                              + player.currentMedia.name);
}
于 2013-08-10T04:21:14.003 回答