C#编写的音乐播放器.docx_第1页
C#编写的音乐播放器.docx_第2页
C#编写的音乐播放器.docx_第3页
C#编写的音乐播放器.docx_第4页
C#编写的音乐播放器.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

主要代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Media;using System.Drawing.Drawing2D;using System.Data.OleDb;namespace MusicPlayer public partial class Form1 : Form public Form1() InitializeComponent(); string MusicFileNames; bool SingleLoop = true; bool AllLoop = true; bool noramal = true; bool RandomLoop = true; #region/播放 private void btnPlay_Click(object sender, EventArgs e) noramal = true; if (this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 0) if (this.listView1.Items.Count 0) timer1.Start(); if (this.listView1.SelectedItems.Count 0) int iPos = this.listView1.SelectedItems0.Index; string FileName = this.listView1.ItemsiPos.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; else MessageBox.Show(请选择歌曲!, 信息提示, MessageBoxButtons.OK, MessageBoxIcon.Information); else this.axWindowsMediaPlayer1.Ctlcontrols.play(); #endregion #region/停止 private void btnStop_Click(object sender, EventArgs e) timer1.Stop(); if (this.listView1.Items.Count 0) if (this.listView1.SelectedItems.Count 0) timer1.Enabled = false; axWindowsMediaPlayer1.Ctlcontrols.stop(); else MessageBox.Show(请选择歌曲!, 信息提示, MessageBoxButtons.OK, MessageBoxIcon.Information); #endregion #region/暂停 private void btnPause_Click(object sender, EventArgs e) timer1.Stop(); if (this.listView1.Items.Count 0) if (this.listView1.SelectedItems.Count 0) timer1.Enabled = false; axWindowsMediaPlayer1.Ctlcontrols.pause(); else MessageBox.Show(请选择歌曲!, 信息提示, MessageBoxButtons.OK, MessageBoxIcon.Information); #endregion #region/上一首 private void btnLast_Click(object sender, EventArgs e) if (this.listView1.SelectedItems.Count 0) int iPos = this.listView1.SelectedItems0.Index; if (iPos 0) this.listView1.ItemsiPos - 1.Selected = true; string FileName = this.listView1.ItemsiPos - 1.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; else MessageBox.Show(这已经是第一首歌曲了!, 信息提示, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(请选择歌曲!, 信息提示, MessageBoxButtons.OK, MessageBoxIcon.Information); #endregion #region/下一首 private void btnNext_Click(object sender, EventArgs e) if (this.listView1.SelectedItems.Count 0) int iPos = this.listView1.SelectedItems0.Index; if (iPos 0) if (this.listView1.SelectedItems.Count 0) int iPos = this.listView1.SelectedItems0.Index; string FileName = this.listView1.ItemsiPos.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; else MessageBox.Show(请选择歌曲!, 信息提示, MessageBoxButtons.OK, MessageBoxIcon.Information); #endregion #region/播放方式(实现循环) private void timer1_Tick(object sender, EventArgs e) /用 timer_tick 来实现循环 int record = this.listView1.SelectedItems0.Index; int iTotal = this.listView1.Items.Count-1; Random rnd = new Random(); /定义随机函数 int rand = rnd.Next(1, iTotal); if (AllLoop = true&noramal=false) if (this.axWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped) if (record this.listView1.Items.Count - 1) this.listView1.Itemsrecord + 1.Selected = true; string FileName = this.listView1.Itemsrecord + 1.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; else if (record = this.listView1.Items.Count - 1) this.listView1.Items0.Selected = true; string FileName = this.listView1.Items0.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; else if (SingleLoop = true&noramal=false) if (this.axWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped) this.listView1.Itemsrecord.Selected = true; this.axWindowsMediaPlayer1.Ctlcontrols.play(); else if (noramal = true) if (this.axWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped) if (record this.listView1.Items.Count - 1) this.listView1.Itemsrecord + 1.Selected = true; string FileName = this.listView1.Itemsrecord + 1.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; else if (record = this.listView1.Items.Count - 1) this.axWindowsMediaPlayer1.Ctlcontrols.stop(); else if (RandomLoop = true & noramal = false) if (this.axWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped) if (record+rand) = this.listView1.Items.Count - 1) this.listView1.Itemsrand.Selected = true; string FileName = this.listView1.Itemsrand.SubItems2.Text; this.axWindowsMediaPlayer1.URL = FileName; #endregion #region/添加文件 private void 添加文件ToolStripMenuItem_Click(object sender, EventArgs e) /添加文件以及其中的信息 this.openFileDialog1.Multiselect=true; if (this.openFileDialog1.ShowDialog() = DialogResult.OK) MusicFileNames = this.openFileDialog1.FileNames; foreach (string MusicName in MusicFileNames) FileInfo MyFileInfo = new FileInfo(MusicName); /曲名 string MyShortFileName = MusicName.Substring(MusicName.LastIndexOf() + 1); MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4); /大小 float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024); /载入 string SubItem = MyShortFileName, MyFileSize.ToString().Substring(0, 4) + M, MusicName ; ListViewItem Item = new ListViewItem(SubItem); this.listView1.Items.Add(Item); this.listView1.Items0.Selected = true; WMPLib.IWMPMedia media = this.axWindowsMediaPlayer1.newMedia(MusicName); this.axWindowsMediaPlayer1.currentPlaylist.appendItem(media); #endregion #region/添加文件夹 private void 添加文件夹ToolStripMenuItem_Click(object sender, EventArgs e) /添加文件夹以及其中文件的信息 if (this.folderBrowserDialog1.ShowDialog() = DialogResult.OK) DirectoryInfo dir = new DirectoryInfo(this.folderBrowserDialog1.SelectedPath); foreach (FileInfo f in dir.GetFiles(*.*) /曲名 string MyShortFileName = f.Name; MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4); /大小 float MyFileSize = (float)f.Length / (1024 * 1024); /载入 string SubItem = MyShortFileName, MyFileSize.ToString().Substring(0, 4) + M,f.FullName ; ListViewItem Item = new ListViewItem(SubItem); this.listView1.Items.Add(Item); this.listView1.Items0.Selected = true; WMPLib.IWMPMedia media = this.axWindowsMediaPlayer1.newMedia(f.DirectoryName); this.axWindowsMediaPlayer1.currentPlaylist.appendItem(media); #endregion #region/播放方式 private void 顺序播放ToolStripMenuItem_Click(object sender, EventArgs e) noramal = true; RandomLoop = false; SingleLoop = false; AllLoop = false; this.顺序播放ToolStripMenuItem.Checked = true; this.单曲播放ToolStripMenuItem.Checked = false; this.全部循环ToolStripMenuItem.Checked = false; this.随机播放ToolStripMenuItem.Checked = false; private void 单曲播放ToolStripMenuItem_Click(object sender, EventArgs e) SingleLoop = true; AllLoop = false; noramal = false; RandomLoop = false; this.顺序播放ToolStripMenuItem.Checked = false; this.单曲播放ToolStripMenuItem.Checked = true; this.全部循环ToolStripMenuItem.Checked = false; this.随机播放ToolStripMenuItem.Checked = false; private void 全部循环ToolStripMenuItem_Click(object sender, EventArgs e) AllLoop = true; SingleLoop = false; noramal = false; RandomLoop = false; this.顺序播放ToolStripMenuItem.Checked = false; this.单曲播放ToolStripMenuItem.Checked = false; this.全部循环ToolStripMenuItem.Checked = true; this.随机播放ToolStripMenuItem.Checked = false; private void 随机播放ToolStripMenuItem_Click(object sender, EventArgs e) RandomLoop = true; SingleLoop = false; AllLoop = false; noramal = false; this.顺序播放ToolStripMenuItem.Checked = false; this.单曲播放ToolStripMenuIte

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论