
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
| public class Player { private AxWMPLib.AxWindowsMediaPlayer myPlayer; private string[] playList; private int numOfMusic; private int currentPlay; public int NumOfMusic { get { return numOfMusic; } } public WMPLib.WMPPlayState playstate { get { return myPlayer.playState; } } public string PlayList(int num) { return playList[num]; } public Player(AxWMPLib.AxWindowsMediaPlayer mediaPlayer) { myPlayer = mediaPlayer; playList = new string[1000]; numOfMusic = 0; } public void AddFile(string path) { if(numOfMusic < 1000) { numOfMusic ++; playList[numOfMusic] = path; } } public void DelFile(int selectNum) { for(int i = selectNum; i <= numOfMusic - 1; i++) { playList[i] = playList[i + 1]; } numOfMusic --; } public void play(int selectNum) { myPlayer.URL = playList[selectNum]; currentPlay = selectNum; } public int NextPlay(int type) { /* type = 0 顺序 type = 1 重复播放全部 type = 2 重复播放一首 type = 3 随机播放 */ switch (type) { case 0: currentPlay ++; if(currentPlay > numOfMusic)return 0; else return currentPlay; case 1: currentPlay ++; if(currentPlay > numOfMusic) return 1; else return currentPlay; case 2: return currentPlay; case 3: Random rdm = new Random(unchecked((int)DateTime.Now.Ticks)); currentPlay = rdm.Next() % numOfMusic; if(currentPlay == 0) return numOfMusic; else return currentPlay; default: return 0; } } } |
| if(this.openFileDialog1.ShowDialog() == DialogResult.OK) { string path = this.openFileDialog1.FileName; FileInfo f = new FileInfo(path); MyPlayer.AddFile(f.FullName); string STRFILE = Convert.ToString(MyPlayer.NumOfMusic); for(int i = 1;i<=5-STRFILE.Length;i++)STRFILE+=’ ’; STRFILE += f.Name; this.listBox1.Items.Add(STRFILE); } |
| private void showfiles(string path,ListBox listBox1) { DirectoryInfo dir = new DirectoryInfo(path); foreach(FileInfo f in dir.GetFiles("*.mp3")) { MyPlayer.AddFile(f.FullName); } foreach(DirectoryInfo f in dir.GetDirectories()) { showfiles(f.FullName,listBox1); } |
| if(listBox1.SelectedIndex >= 0) { listBox1.SelectedIndex --; if(listBox1.SelectedIndex <0)listBox1.SelectedIndex = MyPlayer.NumOfMusic - 1; MyPlayer.play(listBox1.SelectedIndex + 1); } |
| if(listBox1.SelectedIndex >= 0) { listBox1.SelectedIndex = (listBox1.SelectedIndex + 1) % MyPlayer.NumOfMusic; MyPlayer.play(listBox1.SelectedIndex + 1); } |
| private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { if(MyPlayer.playstate == WMPLib.WMPPlayState.wmppsMediaEnded) { timer1.Start(); } } private void timer1_Tick(object sender, System.EventArgs e) { timer1.Stop(); int selectnum = 0; if(menuItem13.Checked)selectnum = MyPlayer.NextPlay(0); else if (menuItem15.Checked)selectnum = MyPlayer.NextPlay(1); else if (menuItem16.Checked)selectnum = MyPlayer.NextPlay(2); else if (menuItem17.Checked)selectnum = MyPlayer.NextPlay(3); if(selectnum != 0) { listBox1.SelectedIndex = selectnum - 1; MyPlayer.play(selectnum); } } |