How to interact with Windows Media Player in C#
Asked Answered
D

4

9

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

Deliberative answered 11/9, 2008 at 13:2 Comment(0)
N
4

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.

Nila answered 11/9, 2008 at 13:8 Comment(5)
Did you mean to link to something...?Irreligion
I think that is what he wanted... a way to access and control a currently running instance of WMP.Irreligion
Thanks a lot, this was exactly what I was looking for, worked like a charm. You solved my problem I spend 2 days solving in like 6mins, awesome! Thanks!Deliberative
The link is 404ed. Can anyone please fix it? Thanks :)Betook
I've found what I believe to be the thread (Same GUID). I have edited the above answer. Waiting for it to be reviewed.Chaschase
G
6

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

Golden answered 11/9, 2008 at 13:9 Comment(1)
this approach cannot interact with the "standalone" WMP instance.Dustheap
O
5

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..

Oedipus answered 19/4, 2009 at 4:47 Comment(1)
The zip with the sample code can be found at the web archive: web.archive.org/web/20061215062200if_/http://…Unrivalled
N
4

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.

Nila answered 11/9, 2008 at 13:8 Comment(5)
Did you mean to link to something...?Irreligion
I think that is what he wanted... a way to access and control a currently running instance of WMP.Irreligion
Thanks a lot, this was exactly what I was looking for, worked like a charm. You solved my problem I spend 2 days solving in like 6mins, awesome! Thanks!Deliberative
The link is 404ed. Can anyone please fix it? Thanks :)Betook
I've found what I believe to be the thread (Same GUID). I have edited the above answer. Waiting for it to be reviewed.Chaschase
M
1

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.

Minard answered 11/9, 2008 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.