C#播放器.docx
《C#播放器.docx》由会员分享,可在线阅读,更多相关《C#播放器.docx(22页珍藏版)》请在冰豆网上搜索。
C#播放器
以下是全部代码:
1.Form1.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Collections;
namespace自制影音播放器
{
publicpartialclassForm1:
Form
publicForm1()
InitializeComponent();
}
ArrayListstrFilenames=newArrayList();//存放完整文件名
privatevoidbutton1_Click(objectsender,EventArgse)
OpenFileDialogopenFile=newOpenFileDialog();
openFile.Multiselect=true;
DialogResultdr=openFile.ShowDialog();
if(dr==DialogResult.OK)
intcount=lstFilm.Items.Count;//记录添加前的项数
//取得文件主名并在列表框中显示
foreach(stringnameinopenFile.FileNames)
strFilenames.Add(name);
lstFilm.Items.Add(System.IO.Path.GetFileNameWithoutExtension(name));
//默认播放刚添加的第一个
lstFilm.SelectedIndex=count;
privatevoidlistBox1_SelectedIndexChanged(objectsender,EventArgse)
Player.URL=strFilenames[lstFilm.SelectedIndex].ToString();
lblTime.Text="00:
00\n"+Player.currentMedia.durationString;
timer1.Enabled=true;
privatevoidbutton2_Click(objectsender,EventArgse)
Player.Ctlcontrols.play();
privatevoidbutton3_Click(objectsender,EventArgse)
Player.Ctlcontrols.pause();
privatevoidbutton4_Click(objectsender,EventArgse)
if(lstFilm.SelectedIndex>0)
lstFilm.SelectedIndex-=1;
else
lstFilm.SelectedIndex=lstFilm.Items.Count-1;
privatevoidbutton5_Click(objectsender,EventArgse)
if(lstFilm.SelectedIndex{lstFilm.SelectedIndex+=1;}else{lstFilm.SelectedIndex=0;}}privatevoidbutton6_Click(objectsender,EventArgse){Player.Ctlcontrols.stop();}privatevoidForm1_Load(objectsender,EventArgse){lblTime.Text="00:00\n00:00";lstFilm.HorizontalScrollbar=true;Player.uiMode="None";}privatevoidtimer1_Tick(objectsender,EventArgse){trackProcess.Value=(int)Player.Ctlcontrols.currentPosition;lblTime.Text=Player.Ctlcontrols.currentPositionString+"\n"+Player.currentMedia.durationString;}//更改媒体所触发的事件privatevoidPlayer_MediaChange(objectsender,AxWMPLib._WMPOCXEvents_MediaChangeEvente){//进度trackProcess.Maximum=(int)Player.currentMedia.duration;trackProcess.Minimum=0;if(trackProcess.Maximum>1000){trackProcess.TickFrequency=trackProcess.Maximum/100;}else{trackProcess.TickFrequency=trackProcess.Maximum/20;}//音量trackVolume.Maximum=100;trackVolume.Minimum=0;trackVolume.TickFrequency=10;trackVolume.Value=Player.settings.volume;lblTime.Text="00:00\n"+Player.currentMedia.durationString;}privatevoidtrackProcess_Scroll(objectsender,EventArgse){Player.Ctlcontrols.currentPosition=trackProcess.Value;}privatevoidtrackVolume_Scroll(objectsender,EventArgse){Player.settings.volume=trackVolume.Value;}privatevoid退出XToolStripMenuItem_Click(objectsender,EventArgse){Application.Exit();}privatevoidtoolStripMenuItem1_Click(objectsender,EventArgse){strFilenames.Clear();lstFilm.Items.Clear();}}2.Program.csusingSystem;usingSystem.Collections.Generic;usingSystem.Windows.Forms;namespace自制影音播放器{staticclassProgram{//////应用程序的主入口点。///[STAThread]staticvoidMain(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(newForm1());}}}3.Form1.Designer.csnamespace自制影音播放器{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){ponents=newSystem.ComponentModel.Container();System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(Form1));this.panel1=newSystem.Windows.Forms.Panel();this.splitter1=newSystem.Windows.Forms.Splitter();this.lstFilm=newSystem.Windows.Forms.ListBox();this.panel2=newSystem.Windows.Forms.Panel();this.panel4=newSystem.Windows.Forms.Panel();this.trackProcess=newSystem.Windows.Forms.TrackBar();this.lblTime=newSystem.Windows.Forms.Label();this.panel3=newSystem.Windows.Forms.Panel();this.panel5=newSystem.Windows.Forms.Panel();this.trackVolume=newSystem.Windows.Forms.TrackBar();this.button6=newSystem.Windows.Forms.Button();this.button5=newSystem.Windows.Forms.Button();this.button4=newSystem.Windows.Forms.Button();this.button3=newSystem.Windows.Forms.Button();this.button2=newSystem.Windows.Forms.Button();this.button1=newSystem.Windows.Forms.Button();this.menuStrip1=newSystem.Windows.Forms.MenuStrip();this.文件FToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();this.打开OToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();this.toolStripMenuItem1=newSystem.Windows.Forms.ToolStripMenuItem();this.toolStripSeparator1=newSystem.Windows.Forms.ToolStripSeparator();this.退出XToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();this.timer1=newSystem.Windows.Forms.Timer(ponents);this.toolTip1=newSystem.Windows.Forms.ToolTip(ponents);this.Player=newAxWMPLib.AxWindowsMediaPlayer();this.panel1.SuspendLayout();this.panel2.SuspendLayout();this.panel4.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.trackProcess)).BeginInit();this.panel3.SuspendLayout();this.panel5.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.trackVolume)).BeginInit();this.menuStrip1.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.Player)).BeginInit();this.SuspendLayout();////panel1//this.panel1.Controls.Add(this.Player);this.panel1.Controls.Add(this.splitter1);this.panel1.Controls.Add(this.lstFilm);this.panel1.Dock=System.Windows.Forms.DockStyle.Fill;this.panel1.Location=newSystem.Drawing.Point(0,24);this.panel1.Name="panel1";this.panel1.Size=newSystem.Drawing.Size(534,289);this.panel1.TabIndex=2;////splitter1//this.splitter1.Location=newSystem.Drawing.Point(131,0);this.splitter1.Name="splitter1";this.splitter1.Size=newSystem.Drawing.Size(3,289);this.splitter1.TabIndex=5;this.splitter1.TabStop=false;////lstFilm//this.lstFilm.Dock=System.Windows.Forms.DockStyle.Left;this.lstFilm.FormattingEnabled=true;this.lstFilm.IntegralHeight=false;this.lstFilm.ItemHeight=12;this.lstFilm.Location=newSystem.Drawing.Point(0,0);this.lstFilm.Name="lstFilm";this.lstFilm.Size=newSystem.Drawing.Size(131,289);this.lstFilm.TabIndex=4;this.toolTip1.SetToolTip(this.lstFilm,"播放文件列表");this.lstFilm.SelectedIndexChanged+=newSystem.EventHandler(this.listBox1_SelectedIndexChanged);////panel2//this.panel2.BackgroundImageLayout=System.Windows.Forms.ImageLayout.None;this.panel2.Controls.Add(this.panel4);this.panel2.Controls.Add(this.panel3);this.panel2.Dock=System.Windows.Forms.DockStyle.Bottom;this.panel2.Location=newSystem.Drawing.Point(0,313);this.panel2.Name="panel2";this.panel2.Size=newSystem.Drawing.Size(534,38);this.panel2.TabIndex=3;////panel4//this.panel4.Controls.Add(this.trackProcess);this.panel4.Controls.Add(this.lblTime);this.panel4.Dock=System.Windows.Forms.DockStyle.Fill;this.panel4.Location=newSystem.Drawing.Point(297,0);this.panel4.Name="panel4";this.panel4.Size=newSystem.Drawing.Size(237,38);this.panel4.TabIndex=1;////trackProcess//this.trackProcess.AutoSize=false;this.trackProcess.Dock=System.Windows.Forms.DockStyle.Fill;this.trackProcess.Location=newSystem.Drawing.Point(71,0);this.trackProcess.Name="trackProcess";this.trackProcess.Size=newSystem.Drawing.Size(166,38);this.trackProcess.TabIndex=0;this.toolTip1.SetToolTip(this.trackProcess,"播放进度,可以通过拖动滑块进行调节");this.trackProcess.Scroll+=newSystem.EventHandler(this.trackProcess_Scroll);////lblTime//this.lblTime.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;this.lblTime.Dock=System.Windows.Forms.DockStyle.Left;this.lblTime.Font=newSystem.Drawing.Font("宋体",10.5F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));this.lblTime.Location=newSystem.Drawing.Point(0,0);this.lblTime.Name="lblTime";this.lblTime.Size=newSystem.Drawing.Size(71,38);this.lblTime.TabIndex=1;this.lblTime.TextAlign=System.Drawing.ContentAlignment.MiddleCenter;this.toolTip1.SetToolTip(this.lblTime,"已播放时间/总时间");////panel3//this.panel3.Controls.Add(this.panel5);this.panel3.Controls.Add(this.button6);this.panel3.Controls.Add(this.button5);this.panel3.Controls.Add(this.button4);this.panel3.Controls.Add(this.button3);this.panel3.Controls.Add(this.button2);this.panel3.Controls.Add(this.button1);this.panel3.Dock=System.Windows.Forms.DockStyle.Left;this.panel3.Location=newSystem.Drawing.Point(0,0);this.panel3.Name="panel3";this.panel3.Size=newSystem.Drawing.Size(297,38);this.panel3.TabIndex=0;////panel5//this.panel5.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;this.panel5.Controls
lstFilm.SelectedIndex+=1;
lstFilm.SelectedIndex=0;
privatevoidbutton6_Click(objectsender,EventArgse)
Player.Ctlcontrols.stop();
privatevoidForm1_Load(objectsender,EventArgse)
00\n00:
00";
lstFilm.HorizontalScrollbar=true;
Player.uiMode="None";
privatevoidtimer1_Tick(objectsender,EventArgse)
trackProcess.Value=(int)Player.Ctlcontrols.currentPosition;
lblTime.Text=Player.Ctlcontrols.currentPositionString+"\n"+Player.currentMedia.durationString;
//更改媒体所触发的事件
privatevoidPlayer_MediaChange(objectsender,AxWMPLib._WMPOCXEvents_MediaChangeEvente)
//进度
trackProcess.Maximum=(int)Player.currentMedia.duration;
trackProcess.Minimum=0;
if(trackProcess.Maximum>1000)
trackProcess.TickFrequency=trackProcess.Maximum/100;
trackProcess.TickFrequency=trackProcess.Maximum/20;
//音量
trackVolume.Maximum=100;
trackVolume.Minimum=0;
trackVolume.TickFrequency=10;
trackVolume.Value=Player.settings.volume;
privatevoidtrackProcess_Scroll(objectsender,EventArgse)
Player.Ctlcontrols.currentPosition=trackProcess.Value;
privatevoidtrackVolume_Scroll(objectsender,EventArgse)
Player.settings.volume=trackVolume.Value;
privatevoid退出XToolStripMenuItem_Click(objectsender,EventArgse)
Application.Exit();
privatevoidtoolStripMenuItem1_Click(objectsender,EventArgse)
strFilenames.Clear();
lstFilm.Items.Clear();
2.Program.cs
staticclassProgram
///
///应用程序的主入口点。
[STAThread]
staticvoidMain()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(newForm1());
3.Form1.Designer.cs
partialclassForm1
///必需的设计器变量。
privateSystem.ComponentModel.IContainercomponents=null;
///清理所有正在使用的资源。
///如果应释放托管资源,为true;否则为false。
protectedoverridevoidDispose(booldisposing)
if(disposing&&(components!
=null))
components.Dispose();
base.Dispose(disposing);
#regionWindows窗体设计器生成的代码
///设计器支持所需的方法-不要
///使用代码编辑器修改此方法的内容。
privatevoidInitializeComponent()
ponents=newSystem.ComponentModel.Container();
System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(Form1));
this.panel1=newSystem.Windows.Forms.Panel();
this.splitter1=newSystem.Windows.Forms.Splitter();
this.lstFilm=newSystem.Windows.Forms.ListBox();
this.panel2=newSystem.Windows.Forms.Panel();
this.panel4=newSystem.Windows.Forms.Panel();
this.trackProcess=newSystem.Windows.Forms.TrackBar();
this.lblTime=newSystem.Windows.Forms.Label();
this.panel3=newSystem.Windows.Forms.Panel();
this.panel5=newSystem.Windows.Forms.Panel();
this.trackVolume=newSystem.Windows.Forms.TrackBar();
this.button6=newSystem.Windows.Forms.Button();
this.button5=newSystem.Windows.Forms.Button();
this.button4=newSystem.Windows.Forms.Button();
this.button3=newSystem.Windows.Forms.Button();
this.button2=newSystem.Windows.Forms.Button();
this.button1=newSystem.Windows.Forms.Button();
this.menuStrip1=newSystem.Windows.Forms.MenuStrip();
this.文件FToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();
this.打开OToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1=newSystem.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1=newSystem.Windows.Forms.ToolStripSeparator();
this.退出XToolStripMenuItem=newSystem.Windows.Forms.ToolStripMenuItem();
this.timer1=newSystem.Windows.Forms.Timer(ponents);
this.toolTip1=newSystem.Windows.Forms.ToolTip(ponents);
this.Player=newAxWMPLib.AxWindowsMediaPlayer();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackProcess)).BeginInit();
this.panel3.SuspendLayout();
this.panel5.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackVolume)).BeginInit();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.Player)).BeginInit();
this.SuspendLayout();
//
//panel1
this.panel1.Controls.Add(this.Player);
this.panel1.Controls.Add(this.splitter1);
this.panel1.Controls.Add(this.lstFilm);
this.panel1.Dock=System.Windows.Forms.DockStyle.Fill;
this.panel1.Location=newSystem.Drawing.Point(0,24);
this.panel1.Name="panel1";
this.panel1.Size=newSystem.Drawing.Size(534,289);
this.panel1.TabIndex=2;
//splitter1
this.splitter1.Location=newSystem.Drawing.Point(131,0);
this.splitter1.Name="splitter1";
this.splitter1.Size=newSystem.Drawing.Size(3,289);
this.splitter1.TabIndex=5;
this.splitter1.TabStop=false;
//lstFilm
this.lstFilm.Dock=System.Windows.Forms.DockStyle.Left;
this.lstFilm.FormattingEnabled=true;
this.lstFilm.IntegralHeight=false;
this.lstFilm.ItemHeight=12;
this.lstFilm.Location=newSystem.Drawing.Point(0,0);
this.lstFilm.Name="lstFilm";
this.lstFilm.Size=newSystem.Drawing.Size(131,289);
this.lstFilm.TabIndex=4;
this.toolTip1.SetToolTip(this.lstFilm,"播放文件列表");
this.lstFilm.SelectedIndexChanged+=newSystem.EventHandler(this.listBox1_SelectedIndexChanged);
//panel2
this.panel2.BackgroundImageLayout=System.Windows.Forms.ImageLayout.None;
this.panel2.Controls.Add(this.panel4);
this.panel2.Controls.Add(this.panel3);
this.panel2.Dock=System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location=newSystem.Drawing.Point(0,313);
this.panel2.Name="panel2";
this.panel2.Size=newSystem.Drawing.Size(534,38);
this.panel2.TabIndex=3;
//panel4
this.panel4.Controls.Add(this.trackProcess);
this.panel4.Controls.Add(this.lblTime);
this.panel4.Dock=System.Windows.Forms.DockStyle.Fill;
this.panel4.Location=newSystem.Drawing.Point(297,0);
this.panel4.Name="panel4";
this.panel4.Size=newSystem.Drawing.Size(237,38);
this.panel4.TabIndex=1;
//trackProcess
this.trackProcess.AutoSize=false;
this.trackProcess.Dock=System.Windows.Forms.DockStyle.Fill;
this.trackProcess.Location=newSystem.Drawing.Point(71,0);
this.trackProcess.Name="trackProcess";
this.trackProcess.Size=newSystem.Drawing.Size(166,38);
this.trackProcess.TabIndex=0;
this.toolTip1.SetToolTip(this.trackProcess,"播放进度,可以通过拖动滑块进行调节");
this.trackProcess.Scroll+=newSystem.EventHandler(this.trackProcess_Scroll);
//lblTime
this.lblTime.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;
this.lblTime.Dock=System.Windows.Forms.DockStyle.Left;
this.lblTime.Font=newSystem.Drawing.Font("宋体",10.5F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((byte)(134)));
this.lblTime.Location=newSystem.Drawing.Point(0,0);
this.lblTime.Name="lblTime";
this.lblTime.Size=newSystem.Drawing.Size(71,38);
this.lblTime.TabIndex=1;
this.lblTime.TextAlign=System.Drawing.ContentAlignment.MiddleCenter;
this.toolTip1.SetToolTip(this.lblTime,"已播放时间/总时间");
//panel3
this.panel3.Controls.Add(this.panel5);
this.panel3.Controls.Add(this.button6);
this.panel3.Controls.Add(this.button5);
this.panel3.Controls.Add(this.button4);
this.panel3.Controls.Add(this.button3);
this.panel3.Controls.Add(this.button2);
this.panel3.Controls.Add(this.button1);
this.panel3.Dock=System.Windows.Forms.DockStyle.Left;
this.panel3.Location=newSystem.Drawing.Point(0,0);
this.panel3.Name="panel3";
this.panel3.Size=newSystem.Drawing.Size(297,38);
this.panel3.TabIndex=0;
//panel5
this.panel5.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;
this.panel5.Controls
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1