您的位置:首页 > 其它

用QuartzTypeLib.dll播放视频

2013-01-30 16:05 316 查看
播放选定的文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MediaApp
{
public partial class Form1 : Form
{
private const int WS_CHILD = 0x40000000;
private const int WS_CLIPCHILDREN = 0x2000000;
private QuartzTypeLib.IMediaControl MyControl = null;
private QuartzTypeLib.IVideoWindow MyWindow = null;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog MyDialog = new OpenFileDialog();
MyDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
if (MyDialog.ShowDialog() == DialogResult.OK)
{
try
{
QuartzTypeLib.FilgraphManager MyManager = new QuartzTypeLib.FilgraphManager();
if (MyControl != null) MyControl.Stop();//如果已经播放过,则先停止
MyManager.RenderFile(MyDialog.FileName);//加载音频、视频文件
MyWindow = (QuartzTypeLib.IVideoWindow)MyManager;
try//音频文件不需要用pictureBox1,所以会报错
{
MyWindow.Owner = (int)pictureBox1.Handle;
MyWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
MyWindow.SetWindowPosition(pictureBox1.ClientRectangle.Left,pictureBox1.ClientRectangle.Top,pictureBox1.ClientRectangle.Width,pictureBox1.ClientRectangle.Height);
}
catch { }
MyControl = (QuartzTypeLib.IMediaControl)MyManager;
MyControl.Run();
}
catch(Exception Mye)
{
MessageBox.Show(this,Mye.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
}
}

播放指定的文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private const int WS_CHILD = 0x40000000;
private const int WS_CLIPCHILDREN = 0x2000000;
private QuartzTypeLib.IMediaControl MyControl = null;
private QuartzTypeLib.IVideoWindow MyWindow = null;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try
{

QuartzTypeLib.FilgraphManager MyManager = new QuartzTypeLib.FilgraphManager();

if (MyControl != null) MyControl.Stop();//如果已经播放过,则先停止
MyManager.RenderFile("Ending.mpg");//加载音频、视频文件
MyWindow = (QuartzTypeLib.IVideoWindow)MyManager;
try//音频文件不需要用pictureBox1,所以会报错
{
MyWindow.Owner = (int)pictureBox1.Handle;
MyWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
MyWindow.SetWindowPosition(pictureBox1.ClientRectangle.Left, pictureBox1.ClientRectangle.Top, pictureBox1.ClientRectangle.Width, pictureBox1.ClientRectangle.Height);
}
catch { }
MyControl = (QuartzTypeLib.IMediaControl)MyManager;
MyControl.Run();

}
catch (Exception Mye)
{
MessageBox.Show(this, Mye.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: