转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
使用.NET如何实现视频播放中篇         ★★★★

使用.NET如何实现视频播放中篇

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1057 更新时间:2009/6/9 2:34:38
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Red;
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Black;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 28);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(288, 252);
this.panel1.TabIndex = 4;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 260);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(288, 20);
this.statusBar1.TabIndex = 5;
//
// statusBarPanel1
//
this.statusBarPanel1.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanel1.Text = "准备";
this.statusBarPanel1.Width = 144;
//
// statusBarPanel2
//
this.statusBarPanel2.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel2.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanel2.Text = "00:00:00";
this.statusBarPanel2.Width = 64;
//
// statusBarPanel3
//
this.statusBarPanel3.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel3.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.statusBarPanel3.Text = "00:00:00";
this.statusBarPanel3.Width = 64;
//
// FrmTV
//
this.BackColor = System.Drawing.SystemColors.Control;
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.toolBar1);
this.Name = "FrmTV";
this.Size = new System.Drawing.Size(288, 280);
this.SizeChanged += new System.EventHandler(this.FrmTV_SizeChanged);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void CleanUp()
{
if (m_objMediaControl != null)
m_objMediaControl.Stop();

m_CurrentStatus = MediaStatus.Stopped;

if (m_objMediaEventEx != null)
m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

if (m_objVideoWindow != null)
{
m_objVideoWindow.Visible = 0;
m_objVideoWindow.Owner = 0;
}

if (m_objMediaControl != null) m_objMediaControl = null;
if (m_objMediaPosition != null) m_objMediaPosition = null;
if (m_objMediaEventEx != null) m_objMediaEventEx = null;
if (m_objMediaEvent != null) m_objMediaEvent = null;
if (m_objVideoWindow != null) m_objVideoWindow = null;
if (m_objBasicAudio != null) m_objBasicAudio = null;
if (m_objFilterGraph != null) m_objFilterGraph = null;
}

private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(toolBar1.Buttons.IndexOf(e.Button))
{
case 0:
{
#region 打开文件
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";

if (DialogResult.OK == openFileDialog.ShowDialog())
{
CleanUp();

m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(openFileDialog.FileName);

m_objBasicAudio = m_objFilterGraph as IBasicAudio;

try
{
m_objVideoWindow = m_objFilterGraph as IVideoWindow;
m_objVideoWindow.Owner = (int) panel1.Handle;
m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
panel1.ClientRectangle.Top,
panel1.ClientRectangle.Width,
panel1.ClientRectangle.Height);
}
catch (Exception)
{
m_objVideoWindow = null;
}

m_objMediaEvent = m_objFilterGraph as IMediaEvent;

m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

m_objMediaPosition = m_objFilterGraph as IMediaPosition;

m_objMediaControl = m_objFilterGraph as IMediaControl;

this.Text = "DirectShow - [" + openFileDialog.FileName + "]";

m_objMediaControl.Run();
m_CurrentStatus = MediaStatus.Running;

}
break;
#endregion

}
case 1:
{
m_objMediaControl.Run();
m_CurrentStatus = MediaStatus.Running;
break;
}

case 2:
{
m_objMediaControl.Pause();
m_CurrentStatus = MediaStatus.Paused;
break;
}

case 3:
{
m_objMediaControl.Stop();
m_objMediaPosition.CurrentPosition = 0;
m_CurrentStatus = MediaStatus.Stopped;
break;
}
}

UpdateStatusBar();
UpdateToolBar();
}

private void FrmTV_SizeChanged(object sender, System.EventArgs e)
{
if (m_objVideoWindow != null)
{
m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
panel1.ClientRectangle.Top,
panel1.ClientRectangle.Width,
panel1.ClientRectangle.Height);
}
}

private void timer1_Tick(object sender, System.EventArgs e)
{

if (m_CurrentStatus == MediaStatus.Running)
{
UpdateStatusBar();
}
}
protected override void WndProc( ref Message m)
{
if (m.Msg == WM_GRAPHNOTIFY)
{
int lEventCode;
int lParam1, lParam2;

while (true)

[C语言系列]使用C#实现ADSL自动拨号  [Web开发]狂人采集器规则使用详解
[电脑技术]windows7快捷键使用大全  [办公软件]PowerPoint模板使用经验之谈
[办公软件]如何在PowerPoint中使用(插入)Media Player控件播…  [办公软件]如何在PowerPoint中使用(插入、创建)书签及书签的…
[办公软件]如何在PowerPoint中插入(使用)条形码  [办公软件]如何在PowerPoint中制作模板并使用模板
[办公软件]使用PowerPoint制作电子相册教程  [办公软件]可以使用PowerPoint来测试液晶显示器质量
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台