Friday, December 12, 2008

Embedded mplayer


Still, I don't know whether this is useful, but you can try it for fun--I mean it was fun for me. Here it comes:

The sample I post here was created by c# as a WindowsForm, but as I aware there's nothing wrong if you prefer c++.

I'm not sure whether I should rumble about how to create a winform project from Visual Studio, just skip it for now.

Create a winform project, leave everything as default. As showing from the top picture, you drag a button to the form for "stop" and draw another button for "start". I really don't care where you put your buttons or how many you prefer, what they should look like, etc..

Note: at the postion of video window, I put a lable there as pre-opened window, we'll use that window to play media.

Now we come to the job itself, I mean embed mplayer to a window.

Open the Form1.Designer.cs, add a private member:
private System.Diagnostics.Process mplayerP;

Double click the "start" button, it will lead you to the click function:
private void button1_Click(object sender, EventArgs e)
{
int hWnd = mplayerwin.Handle.ToInt32();
string margs = string.Format( @"-wid {0} -vo gl2_stereo yourmedia.wmv", hWnd );
mplayerP = System.Diagnostics.Process.Start("mplayer.exe", margs);
}


Double click the "stop" button:
private void button2_Click(object sender, EventArgs e)
{
mplayerP.Kill();
}


DONE! have fun.

Note: the picture on top was playing video from 3dtv.at, a stereoscopic demo clip.