C#编写的音乐播放器

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

主要代码:

using System;

using System.Collections.Generic;

using ponentModel;

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.SelectedItems[0].Index;

string FileName = this.listView1.Items[iPos].SubItems[2].Text;

this.axWindowsMediaPlayer1.URL = FileName;

}

}

else

{

MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK,

rmation);

}

}

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, rmation);

}

}

#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, rmation);

}

}

#endregion

#region//上一首

private void btnLast_Click(object sender, EventArgs e)

{

if (this.listView1.SelectedItems.Count > 0)

{

int iPos = this.listView1.SelectedItems[0].Index;

if (iPos > 0)

{

this.listView1.Items[iPos - 1].Selected = true;

string FileName = this.listView1.Items[iPos - 1].SubItems[2].Text;

this.axWindowsMediaPlayer1.URL = FileName;

}

else

{

MessageBox.Show("这已经是第一首歌曲了!", "信息提示", MessageBoxButtons.OK, rmation);

}

}

else

{

MessageBox.Show("请选择歌曲!", "信息提示", MessageBoxButtons.OK, rmation);

}

}

#endregion

#region//下一首

private void btnNext_Click(object sender, EventArgs e)

{

if (this.listView1.SelectedItems.Count > 0)

{

int iPos = this.listView1.SelectedItems[0].Index;

if (iPos < this.listView1.Items.Count - 1)

{

this.listView1.Items[iPos + 1].Selected = true;

string FileName = this.listView1.Items[iPos + 1].SubItems[2].Text;

this.axWindowsMediaPlayer1.URL = FileName;

}

else

{

MessageBox.Show("这已经是最后一首歌曲了!", "信息提示", MessageBoxButtons.OK, rmation);

相关文档
最新文档