⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmediaplayer.cs.cs

📁 csharp编写的类似芊芊静听的播放器!
💻 CS
📖 第 1 页 / 共 3 页
字号:
																						 this.menuItem11,
																						 this.menuItem12,
																						 this.menuItem14,
																						 this.menuItem13});
			// 
			// menuItem11
			// 
			this.menuItem11.DefaultItem = true;
			this.menuItem11.Index = 0;
			this.menuItem11.Text = "打开千千静听(&O)";
			this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click);
			// 
			// menuItem12
			// 
			this.menuItem12.Index = 1;
			this.menuItem12.Text = "在线升级(&U)";
			// 
			// menuItem14
			// 
			this.menuItem14.Index = 2;
			this.menuItem14.Text = "-";
			// 
			// menuItem13
			// 
			this.menuItem13.Index = 3;
			this.menuItem13.Text = "退出(&E)";
			this.menuItem13.Click += new System.EventHandler(this.menuItem13_Click);
			// 
			// txtRename
			// 
			this.txtRename.BackColor = System.Drawing.SystemColors.HotTrack;
			this.txtRename.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.txtRename.Location = new System.Drawing.Point(0, 440);
			this.txtRename.Name = "txtRename";
			this.txtRename.Size = new System.Drawing.Size(120, 21);
			this.txtRename.TabIndex = 4;
			this.txtRename.Text = "重命名";
			this.toolTxtRename.SetToolTip(this.txtRename, "双击鼠标即可生效");
			this.txtRename.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtRename_KeyPress);
			
			this.txtRename.DoubleClick += new System.EventHandler(this.txtRename_DoubleClick);
			// 
			// toolTxtRename
			// 
			this.toolTxtRename.AutoPopDelay = 5000;
			this.toolTxtRename.InitialDelay = 100;
			this.toolTxtRename.ReshowDelay = 100;
			// 
			// frmMediaPlayer
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.SteelBlue;
			this.ClientSize = new System.Drawing.Size(466, 488);
			this.Controls.Add(this.txtRename);
			this.Controls.Add(this.lstMusicName);
			this.Controls.Add(this.lstMusic);
			this.Controls.Add(this.WMMusic);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MaximumSize = new System.Drawing.Size(472, 520);
			this.Menu = this.menuMain;
			this.MinimumSize = new System.Drawing.Size(472, 520);
			this.Name = "frmMediaPlayer";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "千千静听";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmMediaPlayer_Closing);
			this.SizeChanged += new System.EventHandler(this.frmMediaPlayer_SizeChanged);
			this.Load += new System.EventHandler(this.frmMediaPlayer_Load);
			((System.ComponentModel.ISupportInitialize)(this.WMMusic)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		static void Main() 
		{
			//Get the running instance.
			Process instance = RunningInstance();
			if (instance == null)
			{
				//There isn't another instance, show our form.
				frmMediaPlayer objFromMediaPlayer=new frmMediaPlayer();
				Application.Run (objFromMediaPlayer);
			}
			else
			{
				//There is another instance of this process.
				HandleRunningInstance(instance);
			}

		}
		private int currentMusicIndex=0;//当前播放的是列表的第几首歌
		private int currentListIndex=0;//当前播放的是第几个列表
		private Array currentMusicNames=null;//当前播放的列表中的包含的所有歌曲
		private Hashtable HTMusic=new Hashtable();
		private bool isStart=false;
		private string currentOpenURL=@"E:\音乐";

		private void frmMediaPlayer_Load(object sender, System.EventArgs e)
		{
			this.txtRename.Visible=false;
			if(File.Exists("TTPlayer.xml"))//当列表文件存在时,调用readAll方法进行加载
			{
				this.readAll();
				return;
			}
			this.lstMusic.Items.Add("[默认列表]");
			this.lstMusic.SelectedIndex=0;
		}

		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			try
			{
				OpenFileDialog ofd = new OpenFileDialog();
				ofd.Filter ="音频文件(*.mp3,*.wma,*.rm,*.wav)|*.mp3;*.wma;*.wav;*.wmv|所有文件(*.*)|*.*";
				//ofd.InitialDirectory = System.Environment.CurrentDirectory;
				ofd.InitialDirectory =this.currentOpenURL;
				ofd.Multiselect=true;
				ofd.Title = "打开音频文件";
				if(ofd.ShowDialog() == DialogResult.OK)
				{
					if(this.lstMusic.Items.Count==0)
					{
						this.lstMusic.Items.Add("[默认列表]");
						this.lstMusic.SelectedIndex=0;
					}
					this.showCurrentList(ofd.FileNames);
					this.timMusic.Interval=1000;
					this.timMusic.Enabled=true;
					this.currentOpenURL=ofd.FileName.ToString();
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("打开音频文件加入列表时错误:"+ex.Message.ToString(),"异常",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);;
			}
		}
		private void showCurrentList(string[] strFileNames)
		{
			if(this.isStart==false)
			{
				this.HTMusic.Add(this.lstMusic.SelectedItem.ToString(),(Array)strFileNames);
				foreach(string strFileName in strFileNames)
				{
					if(this.lstMusicName.FindString(strFileName)==-1)
						this.lstMusicName.Items.Add(strFileName);
				}
				this.currentListIndex=this.lstMusic.SelectedIndex;
				this.currentMusicIndex=0;
				this.lstMusic.SelectedIndex=this.currentListIndex;
				this.lstMusicName.SelectedIndex=this.currentMusicIndex;
				this.WMMusic.URL=strFileNames[0].ToString();
				if(File.Exists(this.WMMusic.URL)==false)
				{
					MessageBox.Show("读取文件路径时出错,找不到文件:"+this.WMMusic.URL,"文件不存在",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
				}
				this.currentMusicNames=(Array)strFileNames;
				this.isStart=true;
			}
			else
			{
				int index=0;
				Array currentList;
				if(this.lstMusicName.Items.Count==0)
				{
					foreach(string str in strFileNames)//计算再次所选的音乐与已经有的中间共有多少个不重复的
					{
						this.lstMusicName.Items.Add(str);
					}
					currentList=Array.CreateInstance(typeof(string),strFileNames.Length);
					foreach(object obj in this.lstMusicName.Items)
					{
						currentList.SetValue(obj.ToString(),index++);
					}
					this.HTMusic.Add(this.lstMusic.SelectedItem.ToString(),currentList);
				}
				else
				{
					int repeatCount=0;
					Array arrTemp=(Array)HTMusic[this.lstMusic.SelectedItem.ToString()];
					foreach(string str in strFileNames)//计算再次所选的音乐与已经有的中间共有多少个不重复的
					{
						if(this.lstMusicName.Items.Contains(str)==false)//<0即为不重复
						{
							repeatCount++;
							this.lstMusicName.Items.Add(str);
						}
					}
					currentList=Array.CreateInstance(typeof(string),repeatCount+arrTemp.Length);
					foreach(object obj in this.lstMusicName.Items)
					{
						currentList.SetValue(obj.ToString(),index++);
					}
					this.HTMusic.Remove(this.lstMusic.SelectedItem.ToString());
					this.HTMusic.Add(this.lstMusic.SelectedItem.ToString(),currentList);
					if(this.lstMusic.SelectedIndex==this.currentListIndex)
						this.currentMusicNames=(Array)this.HTMusic[this.lstMusic.SelectedItem.ToString()];
				}
			}
		}
		private void frmMediaPlayer_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			e.Cancel=true;
			this.WindowState=FormWindowState.Minimized;
			this.Hide();
		}
		private void timMusic_Tick(object sender, System.EventArgs e)
		{
			try
			{
				string strState=this.WMMusic.playState.ToString();
				if(strState=="wmppsStopped")
				{
					if(this.HTMusic.Count==0)
					{
						this.HTMusic.Clear();
						return;
					}
					if(this.currentListIndex==this.lstMusic.SelectedIndex)//
					{
						ArrayList temp=new ArrayList();
						foreach(object obj in this.lstMusicName.Items)
						{
							temp.Add(obj.ToString());
						}
						this.lstMusicName.Items.Clear();
						foreach(object obj in temp)
						{
							this.lstMusicName.Items.Add(obj.ToString());
						}
						temp.Clear();
						currentMusicIndex++;
						if(currentMusicIndex==this.lstMusicName.Items.Count)
							currentMusicIndex=0;
						this.lstMusicName.SelectedIndex=(currentMusicIndex);
						this.WMMusic.URL=this.currentMusicNames.GetValue(currentMusicIndex).ToString();
					}
					else
					{
						currentMusicIndex++;
						if(currentMusicIndex==this.currentMusicNames.Length)
						{
							currentMusicIndex=0;
						}
						this.WMMusic.URL=this.currentMusicNames.GetValue(currentMusicIndex).ToString();
					}
					if(File.Exists(this.WMMusic.URL)==false)
					{
						MessageBox.Show("读取文件路径时出错,找不到文件:"+this.WMMusic.URL,"文件不存在",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
					}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("判断停止状态时错误:"+ex.Message.ToString(),"出现异常",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);;
			}
		}

		private void frmMediaPlayer_SizeChanged(object sender, System.EventArgs e)
		{
			if(this.WindowState==FormWindowState.Minimized)
			{
				this.Hide();
				this.WindowState=FormWindowState.Normal;
			}
		}

		private void ntfMusic_DoubleClick(object sender, System.EventArgs e)
		{
			this.Show();
			this.WindowState=FormWindowState.Normal;
		}

		private void menuItem10_Click(object sender, System.EventArgs e)
		{
			frmAbout f=new frmAbout();
			f.ShowDialog();
		}

		

		private void menuItem11_Click(object sender, System.EventArgs e)
		{
			this.Show();
			this.WindowState=FormWindowState.Normal;
		}
		private void lstMusicName_DoubleClick(object sender, System.EventArgs e)
		{
			try
			{
				if(this.lstMusicName.Items.Count==0)
					return;
				if(this.lstMusicName.SelectedItems.Count==0)
					return;
				this.currentMusicIndex=this.lstMusicName.SelectedIndex;
				this.currentListIndex=this.lstMusic.SelectedIndex;
				this.currentMusicNames=(Array)this.HTMusic[this.lstMusic.SelectedItem.ToString()];
				this.WMMusic.URL=this.lstMusicName.SelectedItem.ToString();
				if(File.Exists(this.WMMusic.URL)==false)
				{
					MessageBox.Show("读取文件路径时出错,找不到文件:"+this.WMMusic.URL,"文件不存在",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
				}
			}
			catch(Exception)
			{
				//MessageBox.Show("双击lstMusicName列表时错误:"+ex.Message.ToString(),"出现异常",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
			}
		}
		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			if(this.lstMusic.Items.Count==15)
			{
				MessageBox.Show("对不起,最多只允许有15个列表!","列表过多",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
				return;
			}
			this.lstMusic.Items.Add(this.getNewListName());
			this.lstMusic.SelectedIndex=this.lstMusic.Items.Count-1;
		}
		private string getNewListName()
		{
			string tempName="";
			for(int index=1;index<=15;index++)
			{
				tempName="新列表"+index;
				if(this.lstMusic.Items.Contains(tempName)==false)
					return tempName;
			}
			return "新列表N";
		}
		private void lstMusic_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				this.lstMusicName.Items.Clear();
				if(this.lstMusic.SelectedItems.Count==0)///////////
					return;
				if(this.HTMusic.ContainsKey(this.lstMusic.SelectedItem)==true)//当选中的列表里面没有歌曲时清空歌曲列表
				{
					foreach(object obj in (Array)HTMusic[this.lstMusic.SelectedItem])
					{
						if(this.lstMusicName.Items.Contains(obj.ToString())==false)
							this.lstMusicName.Items.Add(obj.ToString());
					}
					if(this.currentListIndex==this.lstMusic.SelectedIndex)
						this.lstMusicName.SelectedIndex=this.currentMusicIndex;
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("更改列表选项时错误:"+ex.Message.ToString(),"出现异常",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
			}
		}

		private void lstMusic_DoubleClick(object sender, System.EventArgs e)
		{
			try
			{
				if(this.lstMusicName.Items.Count>0)
				{
					this.currentMusicNames=(Array)HTMusic[this.lstMusic.SelectedItem];
					this.currentListIndex=this.lstMusic.SelectedIndex;
					this.currentMusicIndex=0;
					this.lstMusicName.SelectedIndex=this.currentMusicIndex;
					this.WMMusic.URL=this.currentMusicNames.GetValue(0).ToString();
					if(File.Exists(this.WMMusic.URL)==false)
					{
						MessageBox.Show("读取文件路径时出错,找不到文件:"+this.WMMusic.URL,"文件不存在",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
					}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("双击lstMusic列表时错误:"+ex.Message.ToString(),"异常",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
			}
		}

		private void menuItem4_Click(object sender, System.EventArgs e)//删除列表
		{
			try
			{
				int tempIndex=this.lstMusic.SelectedIndex;
				string tempListName=this.lstMusic.Items[this.currentListIndex].ToString();
				this.HTMusic.Remove(this.lstMusic.SelectedItem);
				this.lstMusic.Items.Remove(this.lstMusic.SelectedItem);
				this.clearAllHT();
				if(tempIndex==this.currentListIndex)
				{
					foreach(object obj in this.lstMusic.Items)
					{
						if(this.HTMusic.ContainsKey(obj.ToString()))
						{
							this.lstMusic.SelectedIndex=this.lstMusic.Items.IndexOf(obj.ToString());
							this.lstMusicName.SelectedIndex=0;
							this.WMMusic.URL=this.lstMusicName.SelectedItem.ToString();
							if(File.Exists(this.WMMusic.URL)==false)
							{
								MessageBox.Show("读取文件路径时出错,找不到文件:"+this.WMMusic.URL,"文件不存在",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
							}
							this.currentListIndex=this.lstMusic.SelectedIndex;
							this.currentMusicIndex=this.lstMusicName.SelectedIndex;
							this.currentMusicNames=(Array)this.HTMusic[obj.ToString()];
							return;
						}
					}
				}
				else
				{
					this.lstMusic.SelectedIndex=this.lstMusic.Items.IndexOf(tempListName);
				}
			}
			catch(Exception ex)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -