c# 视频播放

发表于: 2003-10-15 20:39:21

搞定了,嘿嘿!首先非常感谢zoujiaming在邮件中给我指了条路:用C#调用API搞定!!!
使用的是mciSendString API函数
主要参考了zoujiaming 给我的邮件(再次感谢啊!!)
以及http://www.csdn.net/Develop/Read_Article.asp?Id=16269
和http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_mcisendstring.asp

下面是我的一个简单实验代码,通过双击PictureBox播放我机子上的一个视频文件。
有什么问题可以跟贴:)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace APImciTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
/// 
public class LibWrap
{
        [DllImport(("winmm.dll"), EntryPoint="mciSendString", CharSet=CharSet.Auto )]
public static extern int mciSendString
( string lpszCommand, string lpszReturnString, uint cchReturn, int hwndCallback);
}  //此处为API函数声明部分
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
// 
// pictureBox1
// 
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlText;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(292, 273);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
  this.pictureBox1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new Form1());
}

private void pictureBox1_DoubleClick(object sender, System.EventArgs e)   //此处为双击播放应用部分,mciCommand中注意空格
{
PictureBox PlayScreen = new PictureBox();
PlayScreen = this.pictureBox1;
string mciCommand;
mciCommand = "open " + "H:\\12.asf" + " alias MyAVI";
mciCommand = mciCommand + " parent " + PlayScreen.Handle.ToInt32() + " style child";     
LibWrap.mciSendString(mciCommand, null, 0,0);
Rectangle r = PlayScreen.ClientRectangle;
mciCommand = "put MyAVI window at 0 0 "+r.Width +" "+r.Height ;
LibWrap.mciSendString( mciCommand, null, 0, 0);
LibWrap.mciSendString ("play MyAVI", null, 0, 0);

}
}
}
posted on 2013-06-26 17:36  qiulang  阅读(650)  评论(0编辑  收藏  举报