




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大规模优化框架-洞察及研究
- 教体局经费管理制度
- 负载均衡网络流量优化-洞察及研究
- 演艺(经纪)合同格式范本5篇
- 物联网技术支撑的健康风险评估模型-洞察及研究
- 学生食堂安全知识培训课件
- 手扶梯上下井安全培训课件
- 东莞个人税务咨询方案
- 学生灶安全检查培训简报课件
- 手写课件的编写方法
- 秋天的雨 省赛获奖
- JJF 1015-2014计量器具型式评价通用规范
- GB/T 95-2002平垫圈C级
- GB/T 8332-2008泡沫塑料燃烧性能试验方法水平燃烧法
- GB/T 38597-2020低挥发性有机化合物含量涂料产品技术要求
- GB/T 21073-2007环氧涂层七丝预应力钢绞线
- 压力管道特性表
- 胸痛的诊断和鉴别诊断课件整理
- 高级会计师评审个人业绩报告(精选9篇)
- DB45-T 679-2017城镇生活用水定额-(高清可复制)
- 储能型虚拟电厂的建设与思考分析报告
评论
0/150
提交评论