13

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?

Jason
  • 86,222
  • 15
  • 131
  • 146

5 Answers5

8

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

Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
5

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

Andres A.
  • 1,329
  • 2
  • 21
  • 37
4

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

bvanderw
  • 1,065
  • 2
  • 12
  • 20
  • Thanks. You may have answered this question as well: http://stackoverflow.com/questions/2464613/looking-for-a-component-net-or-com-activex-that-can-play-avi-files-in-a-winfor – MusiGenesis Mar 17 '10 at 18:47
  • Have you ever used this? It looks like the sample app can do what I need, but the sample apps for DirectShow.NET don't make much sense to me. I can run it and play a file, and it loops automatically, but all this is done internally and I can't find any way to modify it to play multiple files in succession. – MusiGenesis Mar 17 '10 at 19:55
0

The suggestions from Daok and Brian Genisio are both good options. Let me add a third: DirectShow. Used to be part of DirectX but has now been promoted to the Windows SDK. There are many good C# sample applications to look at, and it gives complete control of the playback.

Community
  • 1
  • 1
Guge
  • 4,569
  • 4
  • 35
  • 47
-1

I would consider using the WPF media controls and just use the ElementHost to put your WPF control inside your WinForms app. I think you will get a much more rich experience.

See System.Windows.Forms.Integration for more information

Brian Genisio
  • 47,787
  • 16
  • 124
  • 167