C#视频播放器,非media Player插件
看来论坛里面的非media player插件音乐播放器,我也写了个视频播放的。代码如下,用directX程序代码:
using System; using System.Collections.Generic; using using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.AudioVideoPlayback; namespace VideoPlayer { public partial class MainForm : Form { private Video video = null; public MainForm() { InitializeComponent(); } private void MainForm_Load(object sender, EventArgs e) { } private void btnView_Click(object sender, EventArgs e) { OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter="视频文件(*.wmv;*.avi)|*.wmv;*.avi;"; if (openDlg.ShowDialog() == DialogResult.OK) { if (this.video != null) { if (this.video.Playing) { this.video.Stop(); } } this.lblFileName.Text = openDlg.FileName; this.video = new Video(openDlg.FileName); int width = this.panPlayOwner.Width; int height = this.panPlayOwner.Height; this.video.Owner = this.panPlayOwner; this.video.Owner.Width = width; this.video.Owner.Height = height; this.video.Play(); } } private void btnPlay_Click(object sender, EventArgs e) { if (this.video != null) { if (this.video.Playing) { this.video.Stop(); } this.video.Play(); } } private void btnPause_Click(object sender, EventArgs e) { if (this.video != null) { if (this.video.Playing) { this.video.Pause(); } } } private void btnStop_Click(object sender, EventArgs e) { if (this.video != null) { if (this.video.Playing) { this.video.Stop(); } } } //区域大小改变 private void panPlayOwner_Resize(object sender, EventArgs e) { int width = this.panPlayOwner.Width; int height = this.panPlayOwner.Height; if (this.video != null) { this.video.Owner.Width = width; this.video.Owner.Height = height; } } private void btnFullScreen_Click(object sender, EventArgs e) { if (this.video != null) { this.video.Fullscreen = true; } } //退出全屏 private void MainForm_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { if (this.video != null) { if (this.video.Fullscreen == true) { this.video.Fullscreen = false; }[local]1[/local] } } } private void panPlayOwner_DoubleClick(object sender, EventArgs e) { if (this.video != null) { if (this.video.Fullscreen) { this.video.Fullscreen = false; } } } } }
VideoPlayer.rar
(125.66 KB)