《基于C的音乐播放器源码.docx》由会员分享,可在线阅读,更多相关《基于C的音乐播放器源码.docx(5页珍藏版)》请在第一文库网上搜索。
1、效果图:我们不一样-大壮编曲:张亮、这么多年的有谁比我更了磨平了那和脾气00:06/04:31CSDN1T技甫实现了基本功能:歌词显示功能;播放功能;切歌功能;进度条拖动播放功能;下面是用到的一些变量1istMusic1ist=new1iSt();存储音乐文件的路径1istMusic1ab1e1ist=new1ist();privatePointMUSiCPos;捕捉鼠标,移动formboo1B1sMusicP1ay;是否播放stringtime1eft;歌曲已播放时长1yricFi1esMusic1yric;歌词boo1isShow=fa1se;歌曲列表显示与隐藏boo1isMute;是否静
2、音intMuteBefore;静音前音量intpIaymode;/播放模式Form11oad中增添了双缓冲功能初始化歌曲列表DirectoryInfodirinfo-newDirectoryInfo(,songzz);Fi1e1nfofi1e1ist=dirinfo.GetFi1esO;stringMusicName;新建播放列表for(inti=0;ifi1e1ist.1ength;i+)if(!Contro1Music1ist.Items.Contains(Path.GetFiIeName(fiIe1isti.Fu11Name)MusicName-fi1e1isti.Fu11Name;Co
3、ntro1Music1ist,Items.Add(Path.GetFi1eName(MusicName);初始化歌词显示区域for(inti=O;i7;i+)1abe11abe1-new1abe1O;1abe1.1ocation-newPoint(30,55+i*45);1abe1.Size=newSize(900,50);1abe1.BackCo1or=Co1or.Transparent;1abe1.ForeCo1or-Co1onWhite;1abe1.Font-newFOnt(微软雅黑”,15);默认播放列表第一首歌if(Contro1Music1ist.Items!=nu11)初始化MU
4、SiC1ist,使默认歌曲为index二。Contro1Music1ist.Se1ectedIndex=0;B1sMusicP1ay=fa1se;初始化进度条trkVo1ume.Va1ue=WrMP1ayer.settings,vo1ume;初始化,准备工作pn1Contro1.BackCo1or=Co1or.FromArgb(127,200,200,200);隐藏音量调节条isMute=fa1se;播放与暂停播放功能:播放暂停B1sMusicP1ay=!B1sMusicP1ay;if(B1sMusicP1ay)播放歌曲WP1ayer.Ct1contro1s.p1ay();/MusicP1ay
5、(Music1istContro1Music1ist.Se1ectedIndex);播放歌词TimeMusic1yric.Enab1ed-true;TimeMusicP1ay.Enab1ed=true;Contro1MusicP1ay.Backgroundimage二Properties.Resources,pause;)e1se暂停歌曲WrMP1ayer.Ct1contro1s.pauseO;双击列表播放功能双击列表播放privatevoidIstMusic1istDoub1eC1ick(objectsender,EventArgse)MusicP1ay(Music1istEcontro1M
6、usic1ist.Se1ectedIndex);播放子功能:各计时器状态设置B1sMusicP1ay=true;TimeMusicP1ay.Enab1ed=true;TimeMusic1yric.Enab1ed=true;音乐播放WMP1ayer.UR1=MusicPath;WMP1ayer.Ct1contro1s.p1ay();设置播放/暂停的图片Contro1MusicP1ay.Backgroundimage=Properties.Resources,pause;从文件路径获取歌词名称string1yricpaths=MusicPath.Sp1it(,string1yricname=Iyr
7、icpathsE1yricpaths.1ength-2;初始化歌词类Music1yric=new1yricFi1esO;Music1yric.1oad1yric(1yricname);初始化歌词显示1abe1改背景图片1oadbgimage(Iyricname);播放模式功能根据播放模式播放if(p1aymode=0)循环播放下一曲index+;if(index-Contro1Music1ist.Items.Count)index=O;)e1seif(pIaymode=1)随机播放下一曲Randomrandom=newRandomO;random.NextO;index=random.Next
8、O%Contro1Music1ist.Items.Count;随机的下一首不能与当前一样歌词类:c1ass1yricFi1espub1ic1istIst1yric=new1ist();pub1icstringFirst1yrics(doub1eCurtime)(intindex=0;intsentine1=4;doub1etime;保存7行代码返回string1yrics=newstring8;stringnew1yric=newstring8;new1yricO=new1yric1=new1yric2=new1yric3=nu11;for(intcount=0;count7;count+)(IyricsEcount=Ist1yricEcount.Str1yric;)foreach(1yric1yricinIst1yric)全部化成doub1e计算如果大于等于就返回歌词time=1yric.Minute*60+1yric.Second+1yric.Mmsec*O.01;if(1yric!=nu11)(if(time=Curtime)new1yric0=new1yric1;new1yric11=new1yric2;new1yric2=new1yric3;完整项目及其源码如下:https:/down1oad,