以上我按照一本教程学习C#实例,组建自己播放器出的问题
代码:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.DirectX.AudioVideoPlayback;
namespace player { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { if (MyVideo == null) { button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; } else { button2.Enabled=true; button3.Enabled=true; button4.Enabled=true; } } private Video MyVideo = null; private void button1_Click(object sender, EventArgs e) { openFileDialog1.InitialDirectory = Application.StartupPath; if (openFileDialog1.ShowDialog() == DialogResult.OK) { int height = p1.Height; int width = p1.Width; if (MyVideo != null) { MyVideo.Dispose(); } MyVideo = new Video(openFileDialog1.FileName); MyVideo.Owner=p1; p1.Height=height; p1.Width=width; MyVideo.Play(); MyVideo.Pause(); } if(MyVideo==null) { button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; } else { button2.Enabled=true; button3.Enabled=true; button4.Enabled=true; } }
private void button2_Click(object sender, EventArgs e) { if (MyVideo != null) { MyVideo.Play(); } }
private void button3_Click(object sender, EventArgs e) { if (MyVideo != null) { MyVideo.Stop(); } }
private void button4_Click(object sender, EventArgs e) { if (MyVideo != null) { MyVideo.Play(); } } } }
代码太凌乱了,能否整理下?