I added a reference to the following two dlls:
C:\Windows\System32\wmp.dll
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\AxInterop.WMPLib.dll
using AxWMPLib;
private void Form1_Load(object sender, EventArgs e)
{
Console.WriteLine("Test WMP Control");
this.Closing += new CancelEventHandler(this.Form1_Closing);
}
AxWMPLib.AxWindowsMediaPlayer wmp = null;
private void InitiateWMP()
{
string link = @"C:\Users\MM\Videos\Video\lighthouse.mpg";
wmp = new AxWMPLib.AxWindowsMediaPlayer();
wmp.Enabled = true;
wmp.Location = new System.Drawing.Point(0, 0);
wmp.Name = "wmp";
wmp.Size = new System.Drawing.Size(800, 600);
this.Controls.Add(wmp);
wmp.URL = link;
}
public void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (this.Controls.ContainsKey ("wmp"))
{
this.Controls.RemoveByKey("wmp");
wmp.close();
wmp.Dispose();
wmp = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
InitiateWMP();
}