阅读量:0
在C#中实现MediaPlayer的视频播放功能可以使用Windows Media Player控件。以下是一个简单的示例代码:
using System; using System.Windows.Forms; namespace VideoPlayer { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // 创建Windows Media Player控件 WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayer(); // 设置视频文件的路径 wmp.URL = "C:\\example.mp4"; // 将Windows Media Player控件添加到窗体中 this.Controls.Add(wmp); // 播放视频 wmp.controls.play(); } } }
在这个示例中,我们首先创建了一个WindowsMediaPlayer
对象,并设置了视频文件的路径。然后将WindowsMediaPlayer
控件添加到窗体中,并调用play()
方法来播放视频。
请注意,您需要将Interop.WMPLib.dll
文件添加到项目引用中才能使用WMPLib
命名空间。
另外,您也可以使用其他第三方库或控件来实现视频播放功能,比如使用VLC
或FFmpeg
等。