使用C#实现MediaPlayer的视频播放功能

avatar
作者
筋斗云
阅读量: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命名空间。

另外,您也可以使用其他第三方库或控件来实现视频播放功能,比如使用VLCFFmpeg等。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!