C # Video Player using Microsoft DirectX
Using System; Using System. Collections. Generic; Using System. ComponentModel; Using System. Data; Using System. Drawing; Using System. Text; Using System. Windows. Forms; Using Microsoft. DirectX. AudioVideoPlayback; Namespace playVideoProject { Public partial class Form1: Form { Private Video myvideo = null; Public Form1 () { InitializeComponent (); } Private void button#click (object sender, EventArgs e) { OpenFile. InitialDirectory = Application. StartupPath; // obtain the initial directory displayed in the dialog box. If (openFile. ShowDialog () = DialogResult. OK) { // Record the size of the panel component Int height = panel1.Height; Int width = panel1.Width; // If an opened Video file exists, release it. If (myvideo! = Null) { Myvideo. Dispose (); } // Open a new Video file Myvideo = new Video (openFile. FileName ); // Allocate the Video file to the created Panel component. Myvideo. Owner = panel1; // Redefines the size of the record panel component Panel1.Width = width; Panel1.Height = height; // Play the first frame of the AVI file, mainly to display it in the panel Myvideo. Play (); Myvideo. Pause (); } // Determine the status of buttons in the form If (myvideo = null) { Button2.Enabled = false; Button3.Enabled = false; Button4.Enabled = false; } Else { Button2.Enabled = true; Button3.Enabled = true; Button4.Enabled = true; } } Private void button3_Click (object sender, EventArgs e) { If (myvideo! = Null) { Myvideo. Pause (); } } Private void button2_Click (object sender, EventArgs e) { If (myvideo! = Null) { Myvideo. Play (); } } 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 void button4_Click (object sender, EventArgs e) { If (myvideo! = Null) { Myvideo. Stop (); } } Private void panelappspaint (object sender, PaintEventArgs e) { } } }
|