C#从Windows Media Player获取当前歌曲源URL

时间:2013-08-10 04:14:55

标签: c# api com wmplib

我正在尝试创建一个小应用程序,通知用户当前在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);

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

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:0)