How to interact with Windows Media Player in C#

eric picture eric · Sep 11, 2008 · Viewed 64.2k times · Source

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

Answer

Markus Olsson picture Markus Olsson · Sep 11, 2008

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