Microsoft Visual Sudio怎樣做視頻(pín)播放(fàng)器?

發布時間:2010年12月21日      浏覽次數:809 次
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 DirectX實現視頻(pín)播放(fàng)
{
public partial class Form1 : Form
{
private Video MyVideo = null;
public Form1()
{
InitializeComponent();
//private Video MyVideo = null;
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = Application.StartupPath ;
if ( openFileDialog1.ShowDialog ( ) == DialogResult.OK )
{
// 記錄panel組件的大(dà)小(xiǎo)
int height = panel1.Height ;
int width = panel1.Width ;
// 如果存在打開(kāi)的Video文件,釋放(fàng)它
if ( MyVideo != null )
{
MyVideo.Dispose ( ) ;
}
//MessageBox.Show(openFileDialog1.FileName);
// 打開(kāi)一(yī)個新的Video文件
MyVideo = new Video(openFileDialog1.FileName) ;
// 把Video文件分(fēn)配給創建的Panel組件
MyVideo.Owner = panel1 ;
// 以記錄的panel組件的大(dà)小(xiǎo)來重新定義
panel1.Width = width ;
panel1.Height = height ;
// 播放(fàng)AVI文件的第一(yī)幀,主要是爲了在panel中(zhōng)顯示
MyVideo.Play ( ) ;
MyVideo.Pause ( ) ;
}
//确定窗體(tǐ)中(zhōng)的各按鈕狀态
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.Pause();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (MyVideo != null)
{
MyVideo.Stop();
}
}
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;
}
}
}
}
免責聲明:本站相關技術文章信息部分(fēn)來自網絡,目的主要是傳播更多信息,如果您認爲本站的某些信息侵犯了您的版權,請與我(wǒ)(wǒ)們聯系,我(wǒ)(wǒ)們會即時妥善的處理,謝謝合作!