Migwell
Migwell

Reputation: 20107

How do I get Media Player to *play* using C#?

I'm writing an app to control an existing instance of WMP using C#.

Currently my code goes something like this:

private const int WM_COMMAND = 0x111;
private const int WMP9_PLAY = 0x4978;
SendMessage(WMP.MainWindowHandle, WM_COMMAND, WMP9_PLAY, 0);

This works fine for pausing media player, but if media player is paused or stopped, it skips to the next track. The command is called play, but I could have the wrong value for it. Does anyone either have a better value for WMP9_PLAY, or a better way to make WMP play?

Upvotes: 4

Views: 1118

Answers (2)

Migwell
Migwell

Reputation: 20107

By using Spy++ (from the answer above) I was able to find another set of SendMessage parameters that is sent when you press the play/pause on a windows keyboard that does the job:

SendMessage(WMP.MainWindowHandle, 0xC02B, 0x0000000C, 0x000E0000);

Upvotes: 2

James Hill
James Hill

Reputation: 61793

Check out the sample code here: Interoperating with Windows Media Player using P/Invoke and C#

Upvotes: 1

Related Questions