2C#课程设计报告音乐播放器
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e) {
if (this.listView1.SelectedItems.Count > 0) {
int iSel = this.listView1.SelectedItems[0].Index; this.Text = this.listView1.SelectedItems[0].SubItems[1].Text.Trim(); if(iSel<=this.axWindowsMediaPlayer1.currentPlaylist.count) {
Viscual C#编程实例
一、任务目标 通过建立实例“音乐播放器”,来掌握 windows 应用窗体。 二、功能实现 实现的功能有: 播放模式:顺序,列表,随机,单曲。 添加文件:添加单个文件,添加文件夹。 删除文件:选中的,重复的,错误的以及全部。 播放歌曲:播放,暂停。 可以添加的文件有*.MP3,*.Wma,*.swf,* .wmv,* .avi 文件。 三、关键代码 public partial class Form1 : Form
{ //
this.axWindowsMediaPlayer1.Ctlcontrols.playItem(this.axWindowsMediaPlayer1.currentPlayl ist.get_Item(index));
this.listView1.Items[index].Selected = true; this.listView1.Focus(); this.listView1.Items[index].EnsureVisible(); this.Text = this.listView1.Items[index].SubItems[1].Text; break; } } break; case WMPLib.WMPPlayState.wmppsReady: this.axWindowsMediaPlayer1.Ctlcontrols.play(); break; } }
this.axWindowsMediaPlayer1.currentPlaylist.appendItem(this.axWindowsMediaPlayer1.newMed ia(lvi[i].SubItems[2].Text));
this.listView1.Items.Add(lvi[i]);
{ for (int i = 0; i < this.listView1.Items.Count; i++) { this.listView1.Items[i].Remove(); }
}
private void 删?除 y 错洙?误ó文?件 tToolStripMenuItem_Click(object sender, EventArgs e)
a"; } else { 播¥放?列 表括?折?叠蘴 ToolStripMenuItem.Text = "播¥放?列 表括?折?叠
蘴"; }
}
private void 打洙?开 a 文?件 tToolStripMenuItem_Click(object sender, EventArgs e) {
toolStripButton2_Click(null, null); }
}
private void 删?除 y 选?择?文?件 tToolStripMenuItem_Click(object sender, EventArgs e)
{ if (this.listView1.SelectedItems.Count > 0) { int i = this.listView1.SelectedItems[0].Index;
this.axWindowsMediaPlayer1.Ctlcontrols.playItem(this.axWindowsMediaPlayer1.currentPlayl ist.get_Item(iSel));
; } } }
private void 播¥放?列 表括?折?叠蘴 ToolStripMenuItem_Click(object sender, EventArgs e)
this.listView1.Items.Add(lvi); } listView1.EndUpdate(); } }
private void timer1_Tick(object sender, EventArgs e) {
System.Random rdm = new Random(unchecke来自百度文库((int)DateTime.Now.Ticks)); switch (this.axWindowsMediaPlayer1.playState)
} listView1.EndUpdate(); } public Form1() { InitializeComponent(); this.axWindowsMediaPlayer1.stretchToFit = true; this.axWindowsMediaPlayer1.settings.setMode("loop", true); using (RegistryKey userKey = Application.UserAppDataRegistry) {
{ this.splitContainer1.Panel2Collapsed
= !this.splitContainer1.Panel2Collapsed; if (this.splitContainer1.Panel2Collapsed) { 播¥放?列 表括?折?叠蘴 ToolStripMenuItem.Text = "播¥放?列 表括?展 1 开
lf.searchDirectorFile(this.folderBrowserDialog1.SelectedPath); for (int i = 0; i < lvi.Length; i++) { if (lvi[i] == null) { break; } lvi[i].SubItems[0].Text = (listView1.Items.Count + 1).ToString();
private void 打洙?开 a 文?件 t 夹 DToolStripMenuItem_Click(object sender, EventArgs e)
{ toolStripButton1_Click(null,null);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
using (RegistryKey subKey = Application.UserAppDataRegistry) {
subKey.SetValue("MyMedia", this.folderBrowserDialog1.SelectedPath); } }
private void 删?除 y 所ù有瓺文?件 tToolStripMenuItem_Click(object sender, EventArgs e)
{ case WMPLib.WMPPlayState.wmppsTransitioning: case WMPLib.WMPPlayState.wmppsPlaying: int index = 0; while (index < this.axWindowsMediaPlayer1.currentPlaylist.count) { int selectnum = 0; if (顺 3 序ò播¥放?ToolStripMenuItem.Checked) selectnum = 1; else if (单蹋?曲ú循-环·ToolStripMenuItem.Checked) selectnum = 0; else if (全?部?循-环·ToolStripMenuItem.Checked) selectnum = 1; else if (随?机ú播¥放?ToolStripMenuItem.Checked) { selectnum =
ListViewItem lvi = lf.searchFile(strFile[i]); lvi.SubItems[0].Text = (listView1.Items.Count + 1).ToString();
this.axWindowsMediaPlayer1.currentPlaylist.appendItem(this.axWindowsMediaPlayer1.newMed ia(lvi.SubItems[2].Text));
} }
private void toolStripButton1_Click(object sender, EventArgs e) {
if(this.folderBrowserDialog1.ShowDialog()==DialogResult.OK) {
AddFiles(); } }
private void toolStripButton2_Click(object sender, EventArgs e) {
if (this.openFileDialog1.ShowDialog() == DialogResult.OK) {
this.axWindowsMediaPlayer1.currentPlaylist.clear(); listView1.Items.Clear(); listView1.BeginUpdate(); Class1 lf = new Class1(); string[] strFile = this.openFileDialog1.FileNames; for (int i = 0; i < strFile.Length; i++) {
rdm.Next(); } index = (index +
selectnum)%this.axWindowsMediaPlayer1.currentPlaylist.count;
if(this.axWindowsMediaPlayer1.currentMedia.get_isIdentical(this.axWindowsMediaPlayer1.c urrentPlaylist.get_Item(index)))
{ private void AddFiles() { this.axWindowsMediaPlayer1.currentPlaylist.clear(); listView1.Items.Clear(); listView1.BeginUpdate(); Class1 lf = new Class1(); ListViewItem[] lvi =
if ((this.folderBrowserDialog1.SelectedPath = userKey.GetValue("MyMedia") as string) == null)
{ this.folderBrowserDialog1.SelectedPath =
Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); } AddFiles();
{ for (int i = 0; i < this.listView1.Items.Count; i++) { if (!File.Exists(this.listView1.Items[i].SubItems[2].Text.Trim())) { this.listView1.Items[i].Remove(); } } for (int i = 0; i < this.listView1.Items.Count; i++) { this.listView1.Items[i].Text = Convert.ToString(i + 1); }
if (this.listView1.SelectedItems.Count > 0) {
int iSel = this.listView1.SelectedItems[0].Index; this.Text = this.listView1.SelectedItems[0].SubItems[1].Text.Trim(); if(iSel<=this.axWindowsMediaPlayer1.currentPlaylist.count) {
Viscual C#编程实例
一、任务目标 通过建立实例“音乐播放器”,来掌握 windows 应用窗体。 二、功能实现 实现的功能有: 播放模式:顺序,列表,随机,单曲。 添加文件:添加单个文件,添加文件夹。 删除文件:选中的,重复的,错误的以及全部。 播放歌曲:播放,暂停。 可以添加的文件有*.MP3,*.Wma,*.swf,* .wmv,* .avi 文件。 三、关键代码 public partial class Form1 : Form
{ //
this.axWindowsMediaPlayer1.Ctlcontrols.playItem(this.axWindowsMediaPlayer1.currentPlayl ist.get_Item(index));
this.listView1.Items[index].Selected = true; this.listView1.Focus(); this.listView1.Items[index].EnsureVisible(); this.Text = this.listView1.Items[index].SubItems[1].Text; break; } } break; case WMPLib.WMPPlayState.wmppsReady: this.axWindowsMediaPlayer1.Ctlcontrols.play(); break; } }
this.axWindowsMediaPlayer1.currentPlaylist.appendItem(this.axWindowsMediaPlayer1.newMed ia(lvi[i].SubItems[2].Text));
this.listView1.Items.Add(lvi[i]);
{ for (int i = 0; i < this.listView1.Items.Count; i++) { this.listView1.Items[i].Remove(); }
}
private void 删?除 y 错洙?误ó文?件 tToolStripMenuItem_Click(object sender, EventArgs e)
a"; } else { 播¥放?列 表括?折?叠蘴 ToolStripMenuItem.Text = "播¥放?列 表括?折?叠
蘴"; }
}
private void 打洙?开 a 文?件 tToolStripMenuItem_Click(object sender, EventArgs e) {
toolStripButton2_Click(null, null); }
}
private void 删?除 y 选?择?文?件 tToolStripMenuItem_Click(object sender, EventArgs e)
{ if (this.listView1.SelectedItems.Count > 0) { int i = this.listView1.SelectedItems[0].Index;
this.axWindowsMediaPlayer1.Ctlcontrols.playItem(this.axWindowsMediaPlayer1.currentPlayl ist.get_Item(iSel));
; } } }
private void 播¥放?列 表括?折?叠蘴 ToolStripMenuItem_Click(object sender, EventArgs e)
this.listView1.Items.Add(lvi); } listView1.EndUpdate(); } }
private void timer1_Tick(object sender, EventArgs e) {
System.Random rdm = new Random(unchecke来自百度文库((int)DateTime.Now.Ticks)); switch (this.axWindowsMediaPlayer1.playState)
} listView1.EndUpdate(); } public Form1() { InitializeComponent(); this.axWindowsMediaPlayer1.stretchToFit = true; this.axWindowsMediaPlayer1.settings.setMode("loop", true); using (RegistryKey userKey = Application.UserAppDataRegistry) {
{ this.splitContainer1.Panel2Collapsed
= !this.splitContainer1.Panel2Collapsed; if (this.splitContainer1.Panel2Collapsed) { 播¥放?列 表括?折?叠蘴 ToolStripMenuItem.Text = "播¥放?列 表括?展 1 开
lf.searchDirectorFile(this.folderBrowserDialog1.SelectedPath); for (int i = 0; i < lvi.Length; i++) { if (lvi[i] == null) { break; } lvi[i].SubItems[0].Text = (listView1.Items.Count + 1).ToString();
private void 打洙?开 a 文?件 t 夹 DToolStripMenuItem_Click(object sender, EventArgs e)
{ toolStripButton1_Click(null,null);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
using (RegistryKey subKey = Application.UserAppDataRegistry) {
subKey.SetValue("MyMedia", this.folderBrowserDialog1.SelectedPath); } }
private void 删?除 y 所ù有瓺文?件 tToolStripMenuItem_Click(object sender, EventArgs e)
{ case WMPLib.WMPPlayState.wmppsTransitioning: case WMPLib.WMPPlayState.wmppsPlaying: int index = 0; while (index < this.axWindowsMediaPlayer1.currentPlaylist.count) { int selectnum = 0; if (顺 3 序ò播¥放?ToolStripMenuItem.Checked) selectnum = 1; else if (单蹋?曲ú循-环·ToolStripMenuItem.Checked) selectnum = 0; else if (全?部?循-环·ToolStripMenuItem.Checked) selectnum = 1; else if (随?机ú播¥放?ToolStripMenuItem.Checked) { selectnum =
ListViewItem lvi = lf.searchFile(strFile[i]); lvi.SubItems[0].Text = (listView1.Items.Count + 1).ToString();
this.axWindowsMediaPlayer1.currentPlaylist.appendItem(this.axWindowsMediaPlayer1.newMed ia(lvi.SubItems[2].Text));
} }
private void toolStripButton1_Click(object sender, EventArgs e) {
if(this.folderBrowserDialog1.ShowDialog()==DialogResult.OK) {
AddFiles(); } }
private void toolStripButton2_Click(object sender, EventArgs e) {
if (this.openFileDialog1.ShowDialog() == DialogResult.OK) {
this.axWindowsMediaPlayer1.currentPlaylist.clear(); listView1.Items.Clear(); listView1.BeginUpdate(); Class1 lf = new Class1(); string[] strFile = this.openFileDialog1.FileNames; for (int i = 0; i < strFile.Length; i++) {
rdm.Next(); } index = (index +
selectnum)%this.axWindowsMediaPlayer1.currentPlaylist.count;
if(this.axWindowsMediaPlayer1.currentMedia.get_isIdentical(this.axWindowsMediaPlayer1.c urrentPlaylist.get_Item(index)))
{ private void AddFiles() { this.axWindowsMediaPlayer1.currentPlaylist.clear(); listView1.Items.Clear(); listView1.BeginUpdate(); Class1 lf = new Class1(); ListViewItem[] lvi =
if ((this.folderBrowserDialog1.SelectedPath = userKey.GetValue("MyMedia") as string) == null)
{ this.folderBrowserDialog1.SelectedPath =
Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); } AddFiles();
{ for (int i = 0; i < this.listView1.Items.Count; i++) { if (!File.Exists(this.listView1.Items[i].SubItems[2].Text.Trim())) { this.listView1.Items[i].Remove(); } } for (int i = 0; i < this.listView1.Items.Count; i++) { this.listView1.Items[i].Text = Convert.ToString(i + 1); }