Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Video in a WinForms app

Tags:

c#

winforms

video

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?

like image 267
Jason Avatar asked Dec 01 '08 20:12

Jason


People also ask

How do I add a video to Windows Forms?

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.

Is WinForms outdated?

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.

Does WinForms use MVC?

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.


3 Answers

You can use Media Player inside your Winform. This would been an easy way to do it.

like image 79
Patrick Desjardins Avatar answered Oct 05 '22 03:10

Patrick Desjardins


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

like image 22
Andres A. Avatar answered Oct 05 '22 02:10

Andres A.


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

like image 39
bvanderw Avatar answered Oct 05 '22 02:10

bvanderw