0

可能重复:
如何使用 C# 播放视频文件?

我需要制作一个表单来使用 Visual C# 播放视频,并且视频将在表单中播放

它应该有一个“播放”按钮和“停止”按钮

这个表格的正确代码是什么?

非常感谢您的关心..

4

1 回答 1

1

您可以使用 DirectX 来执行此操作。
首先,您需要下载 DirectX SDK,您可以在此处找到http://msdn.microsoft.com/directx/sdk/
在您的 c# 项目中,添加对 Microsoft.DirectX.AudioVideoPlayback 的引用
然后您可以使用以下内容播放电影的代码

//create the video
Microsoft.DirectX.AudioVideoPlayback.Video video = new Microsoft.DirectX.AudioVideoPlayback.Video(fileName);
//set the System.Windows.Forms.Control to play it in (e.g a panel)
video.Owner = panel1;
//Play the video (put this in a buttons click event)
video.Play();
//Pause the video (put this in a buttons click event)
video.Pause();
//Stop the video (put this in a buttons click event)
video.Stop();

完成后,不要忘记在视频对象上调用 Dispose()。

于 2012-10-13T13:50:07.273 回答