I need to be able to embed and control the playback of an AVI file in a WinForms app, using C#. The video needs to be embedded in the form, not launched in a separate media player window.
What's the best approach to do this? I found the System.Media namespace, which sounded promising, but it appears that is only useful for sound.
Do I use DirectX to do this? MCI? Or some other approach?
In Microsoft Forms, open the form you want to edit. Select the question to which you want to add a video. Select Insert media (picture icon) on the right side of the question.
Win Form has been used to develop many applications. Because of its high age (born in 2003), WinForm was officially declared dead by Microsoft in 2014.
Windows Forms isn't designed from the ground up to use MVC. You have two options. First, you can roll your own implementation of MVC. Second, you can use an MVC framework designed for Windows Forms.
You can use Media Player inside your Winform. This would been an easy way to do it.
The way i did it was, and I quote:
Right-click the Toolbox, and click Choose Items.
Note: If you do not see the Toolbox, click Toolbox on the View menu to open it. The Customize Toolbox Items dialog box opens.
On the COM Components tab, select the Windows Media Player check box, and then click OK.
The Windows Media Player control appears on the current Toolbox tab.
When you add the Windows Media Player control to the Toolbox, Visual Studio automatically adds references to two libraries: AxWMPLib and WMPLib. The next step is to add the control to the Windows Form.
To add the Windows Media Player control to a Windows Form
Drag the Windows Media Player control from the Toolbox to the Windows Form.
In the Properties window, set the Dock property to Fill. You can do this by clicking the center square.
Double-click the title bar of the form to add the default Load event in the Code Editor.
Add the following code to the Form_Load event handler to load a video when the application opens.
axWindowsMediaPlayer1.URL =
@"http://go.microsoft.com/fwlink/?LinkId=95772";
http://msdn.microsoft.com/en-us/library/bb383953(v=vs.90).aspx
I highly recommend this library:
http://directshownet.sourceforge.net/
It is a .NET wrapper around the DirectShow API.
(The sample apps should get you going very quickly.)
--Bruce
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With