您好,欢迎光临本网站![请登录][注册会员]  
文件名称: c#播放器c#播放器
  所属分类: C#
  开发工具:
  文件大小: 109kb
  下载次数: 0
  上传时间: 2011-01-01
  提 供 者: lizhihu*******
 详细说明: 简单的c#播放器! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using QuartzTypeLib;//播放器 using System.Runtime.InteropServices;//播放声音 namespace MYplayer { public partial class mediaplayer : Form { private System.ComponentModel.IContainer components; private const int WM_APP = 0x8000; private const int WM_GRAPHNOTIFY = WM_APP + 1; private const int EC_COMPLETE = 0x01; priva te const int WS_CHILD = 0x40000000; private const int WS_CLIPCHILDREN = 0x2000000; private FilgraphManager m_objFilterGraph = null; private IBasicAudio m_objBasicAudio = null; private IVideoWindow m_objVideoWindow = null; private IMediaEvent m_objMediaEvent = null; private IMediaEventEx m_objMediaEventEx = null; private IMediaPosition m_objMediaPosition = null; private IMediaControl m_objMediaControl = null; enum MediaStatus { None, Stopped, Paused, Running }; private MediaStatus m_CurrentStatus = MediaStatus.None; OpenFileDialog openFileDialog; private int second = 0; private int minute = 0; private int hour = 0; private bool flag = false; public mediaplayer() { InitializeComponent(); this.tsbt_open.Enabled = true; this.tsbt_play.Enabled = false; this.tsbt_stop.Enabled = false; this.tsbt_pause.Enabled = false; } private void tsbt_play_Click(object sender, EventArgs e) { m_objMediaControl.Run(); m_CurrentStatus = MediaStatus.Running; this.tsbt_play.Enabled = false; this.tsbt_stop.Enabled = true; this.tsbt_pause.Enabled = true; this.flag = true; } //播放文件 private void tsbt_pause_Click(object sender, EventArgs e) { m_objMediaControl.Pause(); m_CurrentStatus = MediaStatus.Paused; this.tsbt_play.Enabled = true; this.tsbt_stop.Enabled = true; this.tsbt_pause.Enabled = false; this.flag = false; } //暂停播放 private void tsbt_stop_Click(object sender, EventArgs e) { m_objMediaControl.Stop(); m_objMediaPosition.CurrentPosition = 0; m_CurrentStatus = MediaStatus.Stopped; CleanUp(); this.tsbt_play.Enabled = false; this.tsbt_stop.Enabled = false; this.tsbt_pause.Enabled = false; ToolStripMenuItem_play.Enabled = false; this.flag = false; } //停止播放 private void tsbt_close_Click(object sender, EventArgs e) { m_objMediaControl.Stop(); m_objMediaPosition.CurrentPosition = 0; m_CurrentStatus = MediaStatus.Stopped; CleanUp(); this.tsbt_play.Enabled = false; this.tsbt_stop.Enabled = false; this.tsbt_pause.Enabled = false; ToolStripMenuItem_play.Enabled = true; //this.Close(); } //关闭 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 tsbt_open_Click(object sender, EventArgs e) { 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); try { m_objBasicAudio = m_objFilterGraph as IBasicAudio; m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int)pl_play.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(pl_play.ClientRectangle.Left, pl_play.ClientRectangle.Top, pl_play.ClientRectangle.Width, pl_play.ClientRectangle.Height); } catch (Exception ex) { //MessageBox.Show("该文件不能视频"); 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; this.lb_player1.Text = "就绪......"; this.tsbt_play.Enabled = false; this.tsbt_stop.Enabled = true; this.tsbt_pause.Enabled = true; ToolStripMenuItem_exit.Enabled = true; ToolStripMenuItem_play.Enabled = true; flag = true; this.hour = 0; this.second = 0; this.minute = 0; } }//打开播放文件 private void pl_play_SizeChanged(object sender, EventArgs e) { try { m_objVideoWindow.Owner = (int)pl_play.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(pl_play.ClientRectangle.Left, pl_play.ClientRectangle.Top, pl_play.ClientRectangle.Width, pl_play.ClientRectangle.Height); } catch (Exception ex) { //MessageBox.Show("不支持此类型"); m_objVideoWindow = null; } } //改变窗口 [DllImport("Winmm.dll")] private static extern int waveOutSetVolume(int hwo, System.UInt32 pdwVolume); [DllImport("Winmm.dll")] private static extern int waveOutGetVolume(int hwo, System.UInt32 pdwVolume); //private static extern int waveOutGetVolume(int hwo, out System.UInt32 pdwVolume); private void trackBar1_Scroll(object sender, EventArgs e) { waveOutSetVolume(0, (System.UInt32)((double)0xffff * (double)this.tb_player1.Value / (double)(this.tb_player1.Maximum - this.tb_player1.Minimum))); } //控制声音 private int time(bool Flag ,int s) { string tem = ""; if (Flag) { s++; if (s > 59) { s = 0; minute++; if (minute > 59) { minute = 0; hour++; } } if (hour < 9) tem ="已播放时间:"+ "0" + hour.ToString() + ":"; else tem=hour.ToString() + ":"; if (minute < 9) tem += "0" + minute.ToString() + ":"; else tem += minute.ToString() + ":"; if (s < 9) tem += "0" + s; else tem +=s; this.lb_player2.Text = tem; } return s; } private void tm_play_Tick(object sender, EventArgs e) { second =time(flag, second); } private void ToolStripMenuItem_open_Click(object sender, EventArgs e) { this.tsbt_open_Click(sender, e); ToolStripMenuItem_exit.Enabled = true; } private void ToolStripMenuItem_exit_Click(object sender, EventArgs e) { m_objMediaControl.Stop(); m_objMediaPosition.CurrentPosition = 0; m_CurrentStatus = MediaStatus.Stopped; CleanUp(); this.tsbt_play.Enabled = false; this.tsbt_stop.Enabled = false; this.tsbt_pause.Enabled = false; } private void ToolStripMenuItem_play_Click(object sender, EventArgs e) { this.tsbt_play_Click(sender, e); } private void ToolStripMenuItem_infor_Click(object sender, EventArgs e) { MessageBox.Show("欢迎来到江财C#技术开发组,想了解更多请与小飞联系prophet_zhh@163.com.....", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void mediaplayer_Load(object sender, EventArgs e) { } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 播放器
 输入关键字,在本站1000多万海量源码库中尽情搜索: