实例介绍
【实例简介】
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | 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.Collections; namespace bofangqi { public partial class Form1 : Form { ListSong lst = new ListSong(); //public Form1 myform; public Form1() { lst.mainform = this ; InitializeComponent(); this .skinChang.SkinFile = "DiamondGreen.ssk" ; } private void Form1_Load( object sender, EventArgs e) { this .Size = new Size(484, 402); Point p = new Point(120, 80); this .DesktopLocation = p; this .lst.Show(); } #region 定义数组 public ArrayList MyArrylist = new ArrayList(); public ArrayList List = new ArrayList(); #endregion #region 添加歌曲 private void 打开ToolStripMenuItem_Click( object sender, EventArgs e) { add(); if (AxWmp.playState != WMPLib.WMPPlayState.wmppsPlaying) { this .PlaySong(); } } #endregion #region 基本方法 //添加方法 public void add() { this .odlgFile.Filter = "媒体文件|*.mp3;*.wav;*.wma;*.mid;*.avi;*.mpg;*.asf;*.wmv;*.rmvb" ; if (odlgFile.ShowDialog() == DialogResult.OK) { for ( int i = 0, j = lst.lstSong.Items.Count 1; i < odlgFile.FileNames.Length; i , j ) { if (!List.Contains( this .odlgFile.FileNames[i].Split( '\\' )[ this .odlgFile.FileNames[i].Split( '\\' ).Length - 1])) this .MyArrylist.Add( this .odlgFile.FileNames[i]); string list = this .odlgFile.FileNames[i].Split( '\\' )[ this .odlgFile.FileNames[i].Split( '\\' ).Length - 1]; string SongName = j.ToString() "." this .odlgFile.FileNames[i].Split( '\\' )[ this .odlgFile.FileNames[i].Split( '\\' ).Length - 1]; List.Add(list); lst.lstSong.Items.Add(SongName); } } } //删除歌曲 public void Delete() { if (lst.lstSong.SelectedIndex != -1) { List.RemoveAt(lst.lstSong.SelectedIndex); MyArrylist.RemoveAt(lst.lstSong.SelectedIndex); lst.lstSong.Items.RemoveAt(lst.lstSong.SelectedIndex); lst.lstSong.Items.Clear(); for ( int i = 0; i < List.Count; i ) { int index = i 1; string name = index "." List[i].ToString(); lst.lstSong.Items.Insert(i, name); } this .StopSong(); } } //清空歌曲 public void Clear() { lst.lstSong.Items.Clear(); this .StopSong(); this .MyArrylist.Clear(); this .List.Clear(); } #endregion #region 播放状态 void RePlayState() { ShowSongInfo(); //是否是播放状态 if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPlaying) { this .stbInfo.Text = "正在播放" ; } if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPaused) { this .stbInfo.Text = "暂停" ; } //是否是停止状态、 if (AxWmp.playState == WMPLib.WMPPlayState.wmppsStopped || AxWmp.playState == WMPLib.WMPPlayState.wmppsUndefined) { this .InfoClear(); if (!mIOneMode.Checked && !mIlistMode.Checked) NextSong(); { if (lst.lstSong.Items.Count - 1 > lst.lstSong.SelectedIndex && lst.lstSong.SelectedIndex != -1) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex 1; PlaySong(); } else if (lst.lstSong.Items.Count > 0) { lst.lstSong.SelectedIndex = 0; PlaySong(); } } if (mINone.Checked) { Random r = new Random(); int music = r.Next(1,lst. lstSong.Items.Count); lst.lstSong.SelectedIndex = music; PlaySong(); } if (lst.lstSong.SelectedIndex == -1) this .timerPlay.Enabled = false ; } } #endregion #region 基本控制 //播放 public void PlaySong() { //开始检测播放状态,Timer启动。 this .timerPlay.Enabled = true ; //检查是否选中 if (lst.lstSong.SelectedIndex != -1) { this .AxWmp.URL = this .MyArrylist[lst.lstSong.SelectedIndex].ToString(); this .Text = lst.lstSong.Items[lst.lstSong.SelectedIndex].ToString(); } //检查是否有曲目 else if (lst.lstSong.Items.Count > 0) { lst.lstSong.SelectedIndex = 0; this .AxWmp.URL = this .MyArrylist[lst.lstSong.SelectedIndex].ToString(); this .Text = lst.lstSong.Items[lst.lstSong.SelectedIndex].ToString(); } } //上曲 public void BackSong() { //检测是否是第一首 if (lst.lstSong.SelectedIndex > 0) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex - 1; PlaySong(); } } //下曲 public void NextSong() { if (lst.lstSong.Items.Count - 1 > lst.lstSong.SelectedIndex &&lst. lstSong.SelectedIndex != 1) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex 1; PlaySong(); } //检测是否存在歌曲 else if (lst.lstSong.Items.Count > 0) { lst.lstSong.SelectedIndex = 0; PlaySong(); } } //停止 public void StopSong() { //停止检测播放状态 this .timerPlay.Enabled = false ; this .AxWmp.Ctlcontrols.stop(); InfoClear(); } //暂停 public void PauseSong() { if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPaused) { this .AxWmp.Ctlcontrols.play(); } else { this .AxWmp.Ctlcontrols.pause(); } } //信息重置 void InfoClear() { this .txtName.Text = "欢迎使用" ; this .tkbMove.Maximum = 0; this .tkbMove.Value = 0; this .txtTime.Text = "00:00|00:00" ; this .stbInfo.Text = "就绪" ; } #endregion #region 获取媒体及时信息 void ShowSongInfo() { //wmppsStopped 停止状态,wmppsUndefined 位置状态 if ( this .AxWmp.playState != WMPLib.WMPPlayState.wmppsStopped && this .AxWmp.playState != WMPLib.WMPPlayState.wmppsUndefined) { //获取名称 //this.txtName.Text = this.AxWmp.currentMedia.name; //媒体总长度 this .tkbMove.Maximum = ( int ) this .AxWmp.currentMedia.duration; //媒体当前长度 this .tkbMove.Value = ( int ) this .AxWmp.Ctlcontrols.currentPosition; //显示当前时间 this .txtTime.Text = this .AxWmp.Ctlcontrols.currentPositionString '|' this .AxWmp.currentMedia.durationString; ; } } #endregion #region 歌曲功能控制 //播放按钮 private void btnPlay_Click( object sender, EventArgs e) { PlaySong(); } //停止按钮 private void btnStop_Click( object sender, EventArgs e) { this .timerPlay.Enabled = false ; this .AxWmp.Ctlcontrols.stop(); InfoClear(); } //暂停按钮 private void btnPause_Click( object sender, EventArgs e) { if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPaused) { this .AxWmp.Ctlcontrols.play(); } else { this .AxWmp.Ctlcontrols.pause(); } } //下一曲按钮 private void btnNext_Click( object sender, EventArgs e) { if ( mINone.Checked ) { Random r = new Random(); int music = r.Next(1,lst. lstSong.Items.Count); lst.lstSong.SelectedIndex = music; PlaySong(); } if (lst.lstSong.Items.Count - 1 > lst.lstSong.SelectedIndex && lst.lstSong.SelectedIndex != -1) { lst.lstSong.SelectedIndex =lst. lstSong.SelectedIndex 1; PlaySong(); } } //上一曲按钮 private void btnBack_Click( object sender, EventArgs e) { if (lst.lstSong.SelectedIndex > 0) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex - 1; PlaySong(); } } //快进按钮 private void btnFast_Click( object sender, EventArgs e) { AxWmp.Ctlcontrols.currentPosition = AxWmp.Ctlcontrols.currentPosition 10; } //快退按钮 private void button2_Click( object sender, EventArgs e) { AxWmp.Ctlcontrols.currentPosition = AxWmp.Ctlcontrols.currentPosition - 10; } //每秒刷新信息,TIMER 事件 private void timerPlay_Tick_1( object sender, EventArgs e) { showlrc(); RePlayState(); } //设置当前进度 private void tkbMove_Scroll_1( object sender, EventArgs e) { this .AxWmp.Ctlcontrols.currentPosition = ( double ) this .tkbMove.Value; } #endregion #region 模式控制 //播放循环模式代号 ModeNumber=0,1,2 void PlayMode( int ModeNumber) { if (ModeNumber == 0) { this .mIOneMode.Checked = true ; this .mIlistMode.Checked = false ; this .mINone.Checked = false ; this .AxWmp.settings.playCount = 99; } if (ModeNumber == 1) { this .mIOneMode.Checked = false ; this .mIlistMode.Checked = true ; this .mINone.Checked = false ; this .AxWmp.settings.playCount = 1; } if (ModeNumber == 2) { this .mIOneMode.Checked = false ; this .mIlistMode.Checked = false ; this .mINone.Checked = true ; this .AxWmp.settings.playCount = 1; } } //单曲循环 private void mIOneMode_Click( object sender, EventArgs e) { PlayMode(0); } //顺序播放 private void mIlistMode_Click_1( object sender, EventArgs e) { PlayMode(1); } //随机播放 private void mINone_Click_1( object sender, EventArgs e) { PlayMode(2); } #endregion #region 声音控制 //静音设置 private void chkJy_CheckedChanged( object sender, EventArgs e) { if ( this .chkJy.Checked == true ) { this .AxWmp.settings.volume = 0; this .tkbVol.Enabled = false ; } if ( this .chkJy.Checked == false ) { this .tkbVol.Enabled = true ; this .AxWmp.settings.volume = this .tkbVol.Value; } } //音量 private void tkbVol_Scroll( object sender, EventArgs e) { AxWmp.settings.volume = tkbVol.Value; } #endregion #region 皮肤设置 private void skinOne_Click( object sender, EventArgs e) { this .skinOne.Checked = true ; this .skinTwo.Checked = false ; this .skinThree.Checked = false ; this .skinFour.Checked = false ; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "SportsOrange.ssk" ; } private void skinTwo_Click_1( object sender, EventArgs e) { this .skinOne.Checked = false ; this .skinTwo.Checked = true ; this .skinThree.Checked = false ; this .skinFour.Checked = false ; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "MP10.ssk" ; } private void skinThree_Click_1( object sender, EventArgs e) { this .skinOne.Checked = false ; this .skinTwo.Checked = false ; this .skinThree.Checked = true ; this .skinFour.Checked = false ; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "SportsCyan.ssk" ; } private void skinFour_Click_1( object sender, EventArgs e) { this .skinOne.Checked = false ; this .skinTwo.Checked = false ; this .skinThree.Checked = false ; this .skinFour.Checked = true ; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "SilverColor2.ssk" ; } #endregion #region 全屏功能 //双击鼠标实现全屏播放 private void AxWmp_DoubleClickEvent_1( object sender, AxWMPLib._WMPOCXEvents_DoubleClickEvent e) { this .AxWmp.fullScreen = true ; } //单击鼠标退出全屏 private void AxWmp_ClickEvent( object sender, AxWMPLib._WMPOCXEvents_ClickEvent e) { this .AxWmp.fullScreen = false ; } private void 全屏ToolStripMenuItem_Click( object sender, EventArgs e) { this .AxWmp.fullScreen = true ; } #endregion # region 显示歌词 void showlrc() //歌词显示函数 { //获取当前歌曲播放时间 string time = this .AxWmp.Ctlcontrols.currentPositionString; //获取当前歌曲在列表中的索引号 int n = MyArrylist.IndexOf(AxWmp.URL.ToString()); if (n >= 0) { //得到当前歌曲名 string strlrc = MyArrylist[n].ToString().Split( '.' )[0] ".lrc" ; if (!File.Exists(strlrc)) { this .txtName.Text = "歌词不存在" ; } else { StreamReader Fil = new StreamReader(strlrc, System.Text.Encoding.Default); string strLine = Fil.ReadLine(); while (strLine != null ) { int x = (strLine.IndexOf(time)); if (x != -1) { this .txtName.Text = (strLine.Substring(strLine.LastIndexOf( "]" ) 1, strLine.Length - strLine.LastIndexOf( "]" ) - 1) "\r\n" ); } strLine = Fil.ReadLine(); } } } } #endregion #region 同时移动两个窗体 private void Form1_LocationChanged( object sender, EventArgs e) { lst.Location = new System.Drawing.Point( this .Location.X, this .Location.Y this .Height); } #endregion #region 隐藏列表框 private void chkY_CheckedChanged( object sender, EventArgs e) { if ( this .chkY.Checked == true ) { lst.Hide(); } else { lst.Show(); } } #endregion #region 添加文件夹 public void 添加文件夹ToolStripMenuItem_Click( object sender, EventArgs e) { FolderBrowserDialog Fdialog = new FolderBrowserDialog(); //FolderBrowserDialog Fdialog = new FolderBrowserDialog(); if (Fdialog.ShowDialog() == DialogResult.OK) { string path = Fdialog.SelectedPath; //File.WriteAllText("LoadMusic.txt", path); foreach ( string name in Directory.GetFiles(path)) { FileInfo fileinfo = new FileInfo(name); if (fileinfo.Extension == " .mp3" || fileinfo.Extension == " .wav" || fileinfo.Extension == ".wma" || fileinfo.Extension == ".mid" || fileinfo.Extension == ".avi" || fileinfo.Extension == ".mpgv" || fileinfo.Extension == ".wmv" || fileinfo.Extension == ".rmvb" ) { int i; for (i = 0; i < lst.lstSong.Items.Count; i ) { if (fileinfo.Name == lst.lstSong.Items[i].ToString()) break ; } if (i == lst.lstSong.Items.Count) { lst.lstSong.Items.Add(i " " fileinfo.Name); AxWmp.currentPlaylist.insertItem(AxWmp.currentPlaylist.count, AxWmp.newMedia(i " " fileinfo.Name)); } } } } //if (this.Fdialog.ShowDialog() == DialogResult.OK) //{ // string path = this.Fdialog.SelectedPath; // DirectoryInfo dir = new DirectoryInfo(path); // foreach (FileInfo f in dir.GetFiles("*.mp3 ")) // { // this.lst.lstSong.Items.Add(f.FullName); // } // foreach (FileInfo f in dir.GetFiles("*.mid ")) // { // this.lst.lstSong.Items.Add(f.FullName); // } // foreach (FileInfo f in dir.GetFiles("*.wmv ")) // { // this.lst.lstSong.Items.Add(f.FullName); // } //} } #endregion private void 迷你ToolStripMenuItem_Click( object sender, EventArgs e) { this .menuStrip1.Hide(); this .tkbMove.Hide(); this .tkbVol.Hide(); this .statusStrip1.Hide(); this .lst.Hide(); this .btnShow.Hide(); this .btnFast.Hide(); this .chkJy.Hide(); this .chkY.Hide(); //this.Height = 80; //this.Width = 390; this .AxWmp.Size = new System.Drawing.Size(80, 20); this .AxWmp.Location = new System.Drawing.Point(220, 10); this .btnPlay.Location = new System.Drawing.Point(7, 10); this .btnPause.Location = new System.Drawing.Point(50, 10); this .btnStop.Location = new System.Drawing.Point(93, 10); this .btnBack.Location = new System.Drawing.Point(136, 10); this .btnNext.Location = new System.Drawing.Point(179, 10); this .txtName.Size = new System.Drawing.Size(130, 20); this .txtName.Location = new System.Drawing.Point(305, 10); this .txtTime.Size = new System.Drawing.Size(80, 15); this .txtTime.Location = new System.Drawing.Point(437, 10); this .Size = new System.Drawing.Size(530,80); this .Location = new System.Drawing.Point(120, 0); } private void Form1_DragEnter( object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; else e.Effect = DragDropEffects.None; } private void Form1_DragDrop( object sender, DragEventArgs e) { int n = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).ToString().Length; for ( int i = 0, j = lst.lstSong.Items.Count 1; i < n; i ) { this .AxWmp.URL = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(i).ToString(); string songname = this .AxWmp.URL.Split( '\\' )[ this .AxWmp.URL.Split( '\\' ).Length - 1]; int l =lst.lstSong.Items.Count 1; lst.lstSong.Items.Add((l ).ToString() "." songname); this .MyArrylist.Add( this .AxWmp.URL); this .List.Add((l ).ToString() "." songname); } } //Form2 interSong = new Form2(); //private void 网络音乐ToolStripMenuItem_Click(object sender, EventArgs e) //{ // interSong.Show(); // //interSong.FormClosed =this.interSong.Dispose(); //} } } |
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)