1、音乐播放器开发模块doc音乐播放器开发文档1.动能介绍开始菜单包含:a.添加音乐文件b.添加音乐文件夹c.添加背景图片d.退出播放模式:a.单曲循环 b.顺序循环 c.列表播放 d.随机播放透明度:透明百分之几或不透明界面设置:迷你模式关于:版本信息2、代码讲解全局变量:private SoundPlayer Player = new SoundPlayer(); private SoundPlayer SencondPlayer = new SoundPlayer(); Image image = new Image500;/存放图片数组 private int Imagecount = 0
2、;/计算背景图片数 private int order = 0;/存储图片总数 private int fileCount = 0;/数组中计算音乐文件数 private int fileCount1 = 0;/文件系数 string musicfile = new string500;/存放音乐文件 int selectOne = 0;/双击事件选择的音乐的序号 static int stop = 2;/判断是暂停还是播放 static double CurrentPosition = 0;/获得文件播放的位置 static int State = 0;/当前状态等于时进行单曲循环,等于零的
3、时候进行顺序播放, /当前状态等于时为随机播放/当前状态等于时为列表播放OpenFileDialog openfile = new OpenFileDialog();/打开本地磁盘对话框添加音乐文件private void 添加文件ToolStripMenuItem1_Click(object sender, EventArgs e) fileCount1+; openfile.Filter = |*.mp3; openfile.Multiselect = true;/支持多行文件 try if (DialogResult.OK = openfile.ShowDialog() musicfil
4、efileCount = openfile.FileName; FileInfo fileinfo = new FileInfo(musicfilefileCount); /FileInfo类是将文件去相对路径 string filename = fileCount1.ToString() + _ + fileinfo.Name;/使音乐名前加序号并只取文件名 this.listBox1.Items.Add(filename);/将文件多行显示在列表中 this.musicname.Text = fileinfo.Name; PlayAndStop(fileCount); /启动MP3播放器
5、fileCount+; catch (Exception) MessageBox.Show(musicfilefileCount.ToString(); 添加音乐文件夹private void 添加文件夹ToolStripMenuItem1_Click(object sender, EventArgs e) FolderBrowserDialog folder = new FolderBrowserDialog();/文件夹初始化 folder.ShowDialog(); string file = Directory.GetFiles(folder.SelectedPath.ToString
6、(), *.MP3);/使用数组存得到的文件 int fileName = 0; try foreach (string Music in file) fileCount1+; FileInfo f = new FileInfo(filefileName);/读取文件 musicfilefileCount = filefileName; fileName+; fileCount+;/数组存文件数 string total = fileCount1.ToString() + _ + f.Name;/f.Name只取f中的文件名 this.listBox1.Items.Add(total); ca
7、tch (Exception) MessageBox.Show(输入的音乐总数超出!); 添加背景图片private void 添加背景图片ToolStripMenuItem1_Click(object sender, EventArgs e) FolderBrowserDialog folder = new FolderBrowserDialog(); folder.ShowDialog(); string BGfile = Directory.GetFiles(folder.SelectedPath.ToString(), *.jpg); foreach (string pic in BG
8、file) imageorder = Image.FromFile(pic); order+; this.timer1.Enabled = true;/启动定时器 定时器private void timer1_Tick(object sender, EventArgs e) this.BGpicture.Image = imageImagecount; if (Imagecount = order-1) Imagecount = 0; else Imagecount+; 退出播放器private void 退出ToolStripMenuItem1_Click(object sender, Ev
9、entArgs e) this.Close(); MP3音乐播放器 播放功能/播放MP3文件 private void PlayAndStop(int fileCount) try stop = 3; this.PlayOrStop.Text = 暂停; FileInfo f = new FileInfo(musicfilefileCount); this.musicname.Text = f.Name.ToString();/得到正在播放的音乐名 listBox1.SelectedIndex = fileCount;/自动选中跳转的文件 axWindowsMediaPlayer1.URL =
10、 musicfilefileCount; axWindowsMediaPlayer1.Ctlcontrols.play(); catch (Exception) return; a.单曲循环 private void 单曲循环ToolStripMenuItem1_Click(object sender, EventArgs e) CurrentPosition = axWindowsMediaPlayer1.Ctlcontrols.currentPosition;/得到正在播放的位 axWindowsMediaPlayer1.Ctlcontrols.currentPosition = Curr
11、entPosition;/接着停止的位置继续播放 State = 1; axWindowsMediaPlayer1.settings.setMode(loop, true); b.顺序循环 private void 顺序播放ToolStripMenuItem1_Click(object sender, EventArgs e) State = 0; c.列表播放 private void 列表循环ToolStripMenuItem1_Click(object sender, EventArgs e) State = 3; d.随机播放private void 随机播放ToolStripMenu
12、Item1_Click(object sender, EventArgs e) State = 2; 调用播放模式的事件 /改变播放状态,当音乐一首播放完后转入下一首,有线程调用 private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) Thread thread = new Thread(new ThreadStart(PlayThread); /顺序播放 if (axWindowsMediaPlayer1.playState
13、=WMPLib.WMPPlayState.wmppsMediaEnded & State = 0) try if (selectOne fileCount-2) selectOne = 0; thread.Start(); else selectOne+; thread.Start(); catch (Exception) return; /随机播放 try if (axWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded & State = 2) Random Num = new Random(); int S
14、um = Num.Next(0, fileCount); FileInfo f = new FileInfo(musicfileSum); this.musicname.Text = f.Name; selectOne = Sum; thread.Start(); catch (Exception) return; /列表播放 try if (axWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded & State = 3) if (selectOne fileCount - 2) selectOne = 0;
15、else selectOne+; thread.Start(); catch (Exception) return; 调用线程private void PlayThread() PlayAndStop(selectOne);调用音乐播放功能 制作界面透明功能/透明度% private void toolStripMenuItem7_Click(object sender, EventArgs e) this.Opacity = 0.1; /透明度% private void toolStripMenuItem8_Click(object sender, EventArgs e) this.Op
16、acity = 0.3; /透明度% private void toolStripMenuItem9_Click(object sender, EventArgs e) this.Opacity = 0.5; /透明度% private void toolStripMenuItem10_Click(object sender, EventArgs e) this.Opacity = 0.7; /透明度% private void toolStripMenuItem11_Click(object sender, EventArgs e) this.Opacity = 0.9; /不透明 priv
17、ate void 不透明ToolStripMenuItem1_Click(object sender, EventArgs e) this.Opacity = 1.0; 界面设置private void 迷ToolStripMenuItem_Click(object sender, EventArgs e) Color color = Color.LightGoldenrodYellow; this.musicname.BackColor = color; this.label1.BackColor = color; this.listBox1.BackColor = color; this.
18、Up.BackColor = color; this.PlayOrStop.BackColor = color; this.Down.BackColor = color; this.Stop.BackColor = color; this.MusicText.BackColor = color; this.menu.BackColor = color; this.statusStrip1.BackColor = color; 版本信息private void 版本ToolStripMenuItem1_Click(object sender, EventArgs e) MessageBox.Sh
19、ow(软件版本:.0 正式版n发布时间:.01.19nn新音乐播放器具备音乐播放、歌曲搜索、主题切换、窗口透明等功能,是一款性能卓越、体积“瘦小”、界面绚丽、操作简单的全功能音乐软件;n新音乐播放器满足用户的音乐需要,为您的音乐享受带来更美妙的体验。nntt欢迎大家提出宝贵意见!nntttt思远IT学院nnttt制作人:童新 联系方式QQ:865110135关于软件); 上一曲功能:private void Down_Click(object sender, EventArgs e) try if (selectOne fileCount-1) selectOne+; PlayAndStop(
20、selectOne); else selectOne=0; PlayAndStop(selectOne); catch (Exception) return; 下一曲 private void Up_Click(object sender, EventArgs e) try if (selectOne = 0) selectOne = fileCount1-1; PlayAndStop(selectOne); else selectOne-; PlayAndStop(selectOne); catch (Exception) return; 播放或暂停private void PlayOrSt
21、op_Click(object sender, EventArgs e) try if (stop % 2 = 0)/判断播放或暂停 this.PlayOrStop.Text = 暂停; selectOne = this.listBox1.SelectedIndex; FileInfo f = new FileInfo(musicfileselectOne); this.musicname.Text = f.Name; string playUrl = musicfileselectOne; axWindowsMediaPlayer1.URL = playUrl; axWindowsMedia
22、Player1.Ctlcontrols.currentPosition = CurrentPosition; stop = stop + 1;/当前stop = 3;为暂停状态 axWindowsMediaPlayer1.Ctlcontrols.play(); CurrentPosition = 0; else this.PlayOrStop.Text = 播放; CurrentPosition = axWindowsMediaPlayer1.Ctlcontrols.currentPosition; axWindowsMediaPlayer1.Ctlcontrols.pause(); stop
23、 = stop - 1;/当前stop = 2;为开始状态 catch (Exception) return; 停止音乐播放private void Stop_Click(object sender, EventArgs e) axWindowsMediaPlayer1.Ctlcontrols.stop(); this.PlayOrStop.Text = 播放; stop = 2; 双击播放音乐 /双击事件 private void listBox1_DoubleClick(object sender, EventArgs e) try if (listBox1.SelectedIndex 0)/listBox1.SelectedIndex 选择的对象 selectOne = 1; else selectOne = listBox1.SelectedIndex ; if (listBox1.Items.Count 0)/listBox1.Items.Count listbox中文件的数 listBox1.SelectedIndex = 0; PlayAndStop(selectOne); catch (Exception) return ; 音乐播放器开发文档此文档仅供参考,不的抄袭或盗用!未经本人允许不许再次上传到网上,此文档是初学者的一点心得希望对你有所帮助!
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1