Question

i am trying to create a small application that notifies the user of the path of the current song being played on Windows Media Player.

So i have searched around and came across a good code:

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

But the problem is that this code actually fetches the first song on the list instead of getting the current song, i have tried changing the methods but no good :( and i wish you could help me.

Was it helpful?

Solution

You have it already in 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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top