音乐播放器(VB编程源代码)

上传人:Sc****h 文档编号:139744230 上传时间:2022-08-22 格式:DOC 页数:16 大小:304KB
收藏 版权申诉 举报 下载
音乐播放器(VB编程源代码)_第1页
第1页 / 共16页
音乐播放器(VB编程源代码)_第2页
第2页 / 共16页
音乐播放器(VB编程源代码)_第3页
第3页 / 共16页
资源描述:

《音乐播放器(VB编程源代码)》由会员分享,可在线阅读,更多相关《音乐播放器(VB编程源代码)(16页珍藏版)》请在装配图网上搜索。

1、音乐播放器设计一、先来欣赏一下本音乐播放器的最终效果吧:设计思路很简单,即下面两个窗体的设计。二、主窗体( form1)界面设计如下:主窗体( form1)代码如下:Dim t As Integer, a As BooleanDim p As Integer, b, w As Boolean, onePrivate Sub allclear_Click()清空播放列表List1.ClearForm1.Caption = 无任何曲目 End SubPrivate Sub allloop_Click()全部循环播放Timer3.Enabled = Falseallloop.Checked = Tr

2、ueoneloop.Checked = Falserand.Checked = Falserule.Checked = FalseEnd SubPrivate Sub Form_Load()初始化Form1.Height = 7800w = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Checked = TrueLabel2.Caption = 00:00第一次打开时创建文件If Dir(filepath.text) = And Dir(C:music.txt) = ThenOpen C

3、:filepath.txt For Output As #1Close #1Open C:music.txt For Output As #2Close #2End If读取文件Open C:filepath.txt For Input As #1Open C:music.txt For Input As #2Do While Not EOF(1)Input #1, XInput #2, YIf Dir(X) ThenList1.AddItem (List1.ListCount + 1) & . & YEnd IfLoopClose #1Close #2初始化If List1.ListCoun

4、t 0 Then List1.Selected(0) = TruePicture3(0).Width = 114Picture3(0).Height = 52Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52 Picture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52 Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52

5、Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52 Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52 Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23 a = False初始设置为顺序播放 Label1.Caption = Mid(List1.List(0), InStr(List1.List(0), .) + 1) s

6、d1.Value = 50 音量设置为 50%End SubPrivate Sub List1_DblClick()双击播放a = Truet = 1Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52 End SubPrivate Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If X List1.Width - 430 Thenw = TrueEnd IfEnd SubPriva

7、te Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)伸缩播放列表If X List1.Width - 430 And X 1500 And X 5800 ThenList1.Width = XEnd IfEnd SubPrivate Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)w = FalseEnd SubPrivate Sub List1_Scroll()Li

8、st1.MousePointer = 0End SubPrivate Sub oneloop_Click()单曲循环allloop.Checked = Falseoneloop.Checked = Truerand.Checked = Falserule.Checked = FalseTimer3.Enabled = TrueEnd SubPrivate Sub Pc13_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)播放进度控制Pc13.PaintPicture Pc14.Picture, 0,

9、 0, 233, 17, 234 - X, 0, 233, 17 End IfEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)切换图片If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52 End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0

10、, 114, 52, 0, 0, 114, 52 End IfPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 8

11、3, 52, 0, 0, 83, 52 End SubPrivate Sub Picture10_Click()打开搜索窗体Form2.ShowEnd SubPrivate Sub Picture11_Click()设置静音sd1.Value = 0Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 38, 0, 19, 23End SubPrivate Sub Picture3_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single,

12、Y As Single)If Index = 0 ThenIf a = True Then播放Else暂停End IfEnd IfIf Index = 3 Thenp = 1下一首p = 0End IfIf Index = 2 Thenp = 1上一首p = 0End If停止播放打开音乐文件If Index = 1 ThenCommonDialog1.DialogTitle = 打开音乐文件CommonDialog1.Filter = mp3|*.mp3|wma|*.wmaCommonDialog1.InitDir = D:CommonDialog1.ShowOpenfname = Comm

13、onDialog1.FileTitlegname = CommonDialog1.FileNameIf fname Thenn = Len(fname)For i = 0 To List1.ListCount - 1If Right(List1.List(i), n - 4) = Left(fname, n - 4) Then播放添加后的歌曲Timer1.Enabled = TrueList1.ListIndex = iExit SubEnd IfNextList1.AddItem (List1.ListCount + 1) & . & Left(fname, n - 4)歌曲无重复则添加到播

14、放列表,否则不再添加List1.ListIndex = List1.ListCount - 1List1.Selected(i) = TrueTimer1.Enabled = TrueEnd IfEnd IfEnd SubPrivate Sub Picture3_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)根据不同情况切换图片,实现动态按钮功能If Index = 0 ThenIf t = 0 ThenIf X 80 Or Y 48 ThenPicture3(

15、0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52 ElsePicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 228, 0, 114, 52 End IfEnd IfIf t = 1 ThenIf X 80 Or Y 48 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52 ElsePicture3(0).PaintPicture Pict

16、ure2(1).Picture, 0, 0, 114, 52, 228, 0, 114, 52 End IfEnd IfEnd IfIf Index = 1 ThenIf X 55 Or Y 48 ThenPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52ElsePicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 60, 0, 60, 52 End IfEnd IfIf Index = 2 ThenIf X 65 Or Y 48 Th

17、enPicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52 ElsePicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 83, 0, 83, 52 End IfEnd IfIf Index = 3 ThenIf X 65 Or Y 48 ThenPicture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52 ElsePicture3(3).PaintPict

18、ure Picture2(4).Picture, 0, 0, 83, 52, 166, 0, 83, 52 End IfEnd IfIf Index = 4 ThenIf X 55 Or Y 48 ThenPicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52 ElsePicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 120, 0, 60, 52 End IfEnd IfEnd SubPrivate Sub Picture4_Mouse

19、Move(Button As Integer, Shift As Integer, X As Single, Y As Single)图片切换 If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52 End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52 End IfPicture3(1).PaintPicture Picture2(2).Pic

20、ture, 0, 0, 60, 52, 0, 0, 60, 52 Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52 Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52 Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52 End SubPrivate Sub Picture5_Click()显示或隐藏播放列表If b

21、 = 0 ThenForm1.Width = 5940Form1.Height = 3900b = 1Picture5.ToolTipText = 显示播放列表ElseForm1.Width = 5940Form1.Height = 7800b = 0Picture5.ToolTipText = 隐藏播放列表End IfEnd SubPrivate Sub Picture6_Click()最小化窗体Form1.WindowState = 1End SubPrivate Sub Picture7_Click()关闭窗体之前保存播放列表数据Open C:filepath.txt For Outpu

22、t As #1Open C:music.txt For Output As #2For i = 0 To List1.ListCount - 1n = InStr(List1.List(i), .)Write #2, Mid(List1.List(i), n + 1)NextClose #1Close #2EndEnd SubPrivate Sub Picture8_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)播放模式设置菜单PopupMenu menusetEnd SubPrivate Sub P

23、icture9_Click()删除菜单PopupMenu gclearEnd SubPrivate Sub rand_Click()随机播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Truerule.Checked = FalseEnd SubPrivate Sub rule_Click()顺序播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = False

24、rule.Checked = TrueEnd SubPrivate Sub sd1_Change()音量控制条sd1.ToolTipText = 音量 & sd1.Value & %If sd1.Value = 0 Then sd1.ToolTipText = 静音 If sd1.Value = 100 Then sd1.ToolTipText = 最大音量 If sd1.Value 0 ThenPicture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23End IfEnd SubPrivate Sub select_

25、Click()删除选中项For i = 0 To List1.ListCount - 1If List1.Selected(i) ThenList1.RemoveItem (i)m = iExit ForEnd IfNextFor i = 0 To List1.ListCount - 1n = InStr(List1.List(i), .)List1.List(i) = (i + 1) & . & Mid(List1.List(i), n + 1)NextIf List1.ListCount = 0 Then Exit SubIf List1.ListCount = m ThenList1.S

26、elected(m - 1) = TrueElseList1.Selected(m) = TrueEnd IfEnd SubPrivate Sub Timer1_Timer()更新播放动态If WMP1.playState = 3 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52 a = Truet = 1Picture3(0).ToolTipText = 播放 ElseLabel2.Caption = 00:00Picture3(0).PaintPicture Picture2(0).

27、Picture, 0, 0, 114, 52, 0, 0, 114, 52 a = Falset = 0Picture3(0).ToolTipText = 暂停 End IfEnd IfIf WMP1.playState = 2 Then显示播放进度(时间)End IfPc13.ClsIf WMP1.playState = 3 Or WMP1.playState = 2 ThenPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234- 233*/End IfEnd SubPrivate Sub Timer2_Timer()标题动态显示If WMP1

28、.playState 3 ThenForm1.Caption = 暂停播放 ElseForm1.Caption = 正在播放 End IfEnd IfEnd SubPrivate Sub Timer3_Timer()单曲循环End SubPrivate Sub WMP1_OpenStateChange(ByVal NewState As Long)n = 0If p = 0 ThenFor i = 0 To List1.ListCount - 1IfThenn = n + 1ElseExit ForEnd IfNextone = nLabel1.Caption = Mid(List1.List

29、(n), InStr(List1.List(n), .) + 1) 显示正在播放的曲目 List1.Selected(n) = TrueEnd If显示歌曲总长 End Sub三、副窗体( form1)界面设计如下:说明 :该窗体用于搜索电脑已有歌曲(本音乐播放器的特色所在)副窗体( form1)代码如下:Dim n As Integer, temp(10000) As String, m As IntegerPrivate Sub choose_Click()选择全部歌曲For i = 0 To List2.ListCount - 1List2.Selected(i) = TrueNext

30、iEnd SubPrivate Sub choosenone_Click()清除选择For i = 0 To List2.ListCount - 1List2.Selected(i) = FalseNext iEnd SubPrivate Sub Command1_Click()搜索歌曲并保存Open C:searchresult.txt For Output As #1Open C:geresult.txt For Output As #2List2.ClearDim s As StringCall find(Combo1.Text)If m = n Then s = MsgBox( 搜索完

31、毕 , vbInformation, 提示 )Close #1Close #2End SubPrivate Sub Command2_Click()将选中歌曲添加到播放列表For i = 0 To List2.ListCount - 1t = 0If List2.Selected(i) = True Thenn = Len(List2.List(i)NextIf t = 0 ThenEnd IfEnd IfNext iFor i = 1 To List2.SelCountFor j = 0 To List2.ListCount - 1If List2.Selected(j) ThenList2

32、.RemoveItem jList3.RemoveItem jExit ForEnd IfNext jNext is = MsgBox( 已添加到播放列表, vbInformation, 提示 )End SubPrivate Sub Command3_Click()读取文件(上次最后一次搜索结果)If Dir(C:searchresult.txt) And Dir(C:geresult.txt) ThenOpen C:searchresult.txt For Input As #1Open C:geresult.txt For Input As #2Do While Not EOF(1)Inp

33、ut #1, XInput #2, YList3.AddItem XList2.AddItem YLoopClose #1Close #2s = MsgBox(上次搜索结果读取完成!, vbInformation, 提示 )Elses = MsgBox(没有任何搜索记录!, vbInformation, 提示 )End IfEnd SubPrivate Sub Form_Load()选择搜索条件即路径和文件格式Combo1.Text = Combo1.List(0)Combo2.Text = Combo2.List(0)Form2.Picture = LoadPicture()End SubP

34、rivate Function find1()文件搜索函数Dim i As StringDim a As Integer, b As Integera = m: b = nDim k As IntegerFor k = a To bIf temp(k) = Then Exit Functionfind (temp(k)NextEnd Function*获取该路径下的文件,并且存储目录文件的路径*Private Function find(ByVal path As String) 文件搜索函数Dim i As Stringm = ni = Dir(path, vbDirectory)Do Wh

35、ile i If i . And i . ThenIf (GetAttr(path & i) And vbDirectory) 0 Thentemp(n) = path & i & n = n + 1ElseDoEventsIf Right(i, Len(Combo2.Text) = Combo2.Text ThenList3.AddItem path & iWrite #1, path & iWrite #2, Left(i, Len(i) - 4)List2.AddItem Left(i, Len(i) - 4)End IfEnd IfEnd Ifi = DirLoopfind1End Function总结:本音乐播放器的界面还可以设计的更加漂亮好看, 这个就得发挥你的界面设计能力咯!以上播放器的设计还有很多可以改善的地方, 比如代码能否更加简化?还缺少哪些功能?如何更加赏心悦目?这些就交给你自己去完善咯!另外,为了方便有兴趣的人更好的理解整个设计过程, 我已共享该音乐播放器程序设计的整个工程文件(本程序用到的图片也含有)到以下网址:可以下载看看,希望对你有所帮助!

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!