音乐播放器VB编程源代码_第1页
音乐播放器VB编程源代码_第2页
音乐播放器VB编程源代码_第3页
音乐播放器VB编程源代码_第4页
音乐播放器VB编程源代码_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、二曰蜃誌一二吕音乐播放器设计、先来欣赏一下本音乐播放器的最终效果吧:惜 的 我 杲 口八你o.L2.384.5.6.?.4 4 4 4 4 4 4 4-U.7.8.3 3 311曲泪题眠王的传 I一眇后忘想旧窘) 相还a 俩忑為声上少过悟冷 11轶丽记相西人意驛VW厂?丿.it 至走领-Z 仙 r逵应苗或.-Lnr feL Ttr TJ- Tx TT Ttr TXLT TTr 志士空心志欲晓晓晓晓晓晓畴晓 霧亠TIHTTT壬i3mu4 5 GV 73 3搜素结果张学友-一踣有你张学左-但屈人长久张学茂-你的名字我的姓氏- 口旅学友-分手总要在雨天张学走-吻别-学走光年世?张芋右-目咲女憑民学右

2、-夕阳醉了文件路轻D:kugou 文件格式张学左-夕阳醉了 釆学友-如果这都不算潢 喩字友1心如刀念!I匪学龙-忘,槁或雨丧 2匸找至用儿也建了 张学友-旧情绻绵 张学表-祝福 张学友一生只想跟你走 张惠妹听漓张拍芝-星语心愿 弦子-害不得设计思路很简单,即下面两个窗体的设计二、主窗体(forml)界面设计如下:主窗体(forml)代码如下:Dim t As In teger, a As Boolea nDim p As In teger, b, w As Boolea n, onePrivate Sub allclear_Click()清空播放列表List1.ClearWMP1.curren

3、tPlaylist.ClearForm1.Caption = 无任何曲目 End SubPrivate Sub allloop_Click() 全部循环播放Timer3.Enabled = False allloop.Checked = True oneloop.Checked = False rand.Checked = False rule.Checked = FalseCall WMP1.settings.setMode(loop, True) End SubPrivate Sub Form_Load()初始化 Form1.Height = 7800 w = False allloop.

4、Checked = False oneloop.Checked = False rand.Checked = False rule.Checked = True Label2.Caption = 00:00 第一次打开时创建文件If Dir(filepath.text) = And Dir(C:music.txt) = ThenOpen C:filepath.txt For Output As #1Close #1Open C:music.txt For Output As #2Close #2End If读取文件Open C:filepath.txt For Input As #1Open

5、C:music.txt For Input As #2Do While Not EOF(1) Input #1, X Input #2, Y If Dir(X) ThenList1.AddItem (List1.ListCount + 1) & . & YCall WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(X) End IfLoopClose #1Close #2初始化If List1.ListCount 0 Then List1.Selected(0) = TruePicture3(0)

6、.Width = 114Picture3(0).Height = 52Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52Picture3(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

7、, 0, 60, 52, 0, 0, 60, 52Picture3(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 = FalseCall WMP1.settings.setMode(shuffle, False)初始设置为顺序播放Label1.Caption = Mid(List1.List(0), InStr(List1.List(0), .) + 1) sd1.Valu

8、e = 50 音量设置为 50%End SubPrivate Sub List1_DblClick()双击播放Call WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex) a = True t = 1Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End SubPrivate Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y

9、 As Single) If X List1.Width - 430 Thenw = TrueEnd IfEnd SubPrivate 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 A

10、s Single, Y As Single) w = FalseEnd SubPrivate Sub List1_Scroll()List1.MousePointer = 0End SubPrivate Sub oneloop_Click()单曲循环 allloop.Checked = False oneloop.Checked = True rand.Checked = False rule.Checked = False Timer3.Enabled = True End SubPrivate Sub Pc13_MouseDown(Button As Integer, Shift As I

11、nteger, X As Single, Y As Single) 播放进度控制If WMP1.playState = wmppsPlaying ThenWMP1.Controls.currentPosition = WMP1.currentMedia.duration * X / 233 Pc13.ClsPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - X, 0, 233, 17End IfEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer,

12、 X As Single, Y As Single) 切换图片If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2)

13、.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, 83, 52, 0, 0, 83, 52 End SubPrivate Sub Picture10_Click()打开搜索窗体Form2.ShowEnd SubPrivate Sub Picture11_Click()设置静音 s

14、d1.Value = 0Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 38, 0, 19, 23 End SubPrivate Sub Picture3_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)If Index = 0 ThenIf a = True ThenCall WMP1.Controls.pause 播放ElseCall WMP1.Controls.play 暂停End IfEnd

15、IfIf Index = 3 Thenp = 1Call WMP1.Controls.Next 下一首p = 0End IfIf Index = 2 Thenp = 1Call WMP1.Controls.previous 上一首p = 0End IfIf Index = 4 Then Call WMP1.Controls.stop停止播放打开音乐文件If Index = 1 ThenCommonDialog1.DialogTitle = 打开音乐文件 CommonDialog1.Filter = mp3|*.mp3|wma|*.wma CommonDialog1.InitDir = D:Co

16、mmonDialog1.ShowOpenfname = CommonDialog1.FileTitlegname = CommonDialog1.FileNameIf fname Thenn = Len(fname)For i = 0 To List1.ListCount - 1If Right(List1.List(i), n - 4) = Left(fname, n - 4) ThenCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(i)播放添加后的歌曲Timer1.Enabled = TrueList1.ListIndex = i

17、Exit SubEnd IfNextList1.AddItem (List1.ListCount + 1) & . & Left(fname, n - 4)歌曲无重复则添加到播放列表,否则不再添加Call WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(gname)List1.ListIndex = List1.ListCount - 1List1.Selected(i) = TrueCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(Li

18、st1.ListIndex)Timer1.Enabled = True End If End 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(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0,

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

20、 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 ThenPicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83,

21、 52, 0, 0, 83, 52ElsePicture3(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, 52ElsePicture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 166, 0, 83, 52 End I

22、fEnd IfIf Index = 4 ThenIf X 55 Or Y 48 ThenPicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52ElsePicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 120, 0, 60, 52 End IfEnd IfEnd SubPrivate Sub Picture4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As

23、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).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Pi

24、cture2(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, 83, 52, 0, 0, 83, 52 End SubPrivate Sub Picture5_Click()显示或隐藏播放列表If b = 0 ThenForm1.Width = 5940Form1.Height = 3900b = 1Picture5.To

25、olTipText = 显示播放列表 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 Output As #1Open C:music.txt For Output As #2For i = 0 To List1.L

26、istCount - 1n = InStr(List1.List(i), .)Write #1, WMP1.currentPlaylist.Item(i).sourceURLWrite #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 Picture9_Cli

27、ck()删除菜单PopupMenu gclearEnd SubPrivate Sub rand_Click()随机播放Timer3.Enabled = False allloop.Checked = False oneloop.Checked = False rand.Checked = True rule.Checked = FalseCall WMP1.settings.setMode(shuffle, True)End SubPrivate Sub rule_Click()顺序播放Timer3.Enabled = False allloop.Checked = False oneloop

28、.Checked = False rand.Checked = False rule.Checked = TrueCall WMP1.settings.setMode(shuffle, False)End SubPrivate Sub sd1_Change()音量控制条WMP1.settings.volume = sd1.Value sd1.ToolTipText = 音量 & sd1.Value & % If sd1.Value = 0 Then sd1.ToolTipText = 静音 If sd1.Value = 100 Then sd1.ToolTipText = 最大音量 If sd

29、1.Value 0 ThenPicture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23 End IfEnd SubPrivate Sub select_Click()删除选中项For i = 0 To List1.ListCount - 1If List1.Selected(i) Then List1.RemoveItem (i) m = iCall WMP1.currentPlaylist.RemoveItem(WMP1.currentPlaylist.Item(i) Exit ForEnd IfNextFor i

30、 = 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.Selected(m - 1) = TrueElseList1.Selected(m) = TrueEnd IfEnd SubPrivate Sub Timer1_Timer()更新播放动态If WMP1.currentPlaylist

31、.Count 0 ThenIf WMP1.playState = 3 ThenLabel2.Caption = WMP1.Controls.currentPositionStringPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52 a = True t = 1Picture3(0).ToolTipText = 播放 ElseLabel2.Caption = 00:00Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0

32、, 114, 52 a = False t = 0Picture3(0).ToolTipText = 暂停 End IfEnd IfIf WMP1.playState = 2 ThenLabel2.Caption = WMP1.Controls.currentPositionString显示播放进度(时间)End IfPc13.ClsIf WMP1.playState = 3 Or WMP1.playState = 2 ThenPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - 233 * WMP1.Controls.currentPosi

33、tion / WMP1.currentMedia.duration, 0, 233, 17End IfEnd SubPrivate Sub Timer2_Timer()标题动态显示If WMP1.currentPlaylist.Count 0 ThenIf WMP1.playState 3 ThenForm1.Caption = 暂停播放 + WMP1.currentMedia.getItemInfo(title) ElseForm1.Caption = 正在播放 + WMP1.currentMedia.getItemInfo(title)End IfEnd IfEnd SubPrivate

34、Sub Timer3_Timer()单曲循环If WMP1.currentMedia.duration - 0.5 WMP1.Controls.currentPosition ThenCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(one)End IfEnd SubPrivate Sub WMP1_OpenStateChange(ByVal NewState As Long) n = 0If p = 0 ThenFor i = 0 To List1.ListCount - 1If WMP1.currentPlaylist.Item(i

35、).getItemInfo(title) WMP1.currentMedia.getItemInfo(title) Thenn = n + 1ElseExit ForEnd IfNextone = nLabel1.Caption = Mid(List1.List(n), InStr(List1.List(n), .) + 1) 显示正在播放的曲目List1.Selected(n) = TrueEnd IfLabel3.Caption = WMP1.currentMedia.durationString 显示歌曲总长 End Sub、副窗体(forml )界面设计如下:说明:该窗体用于搜索电脑已

36、有歌曲(本音乐播放器的特色所在) 副窗体(forml)代码如下:Dim n As Integer, temp(IOOOO) As String, m As IntegerPrivate Sub choose_Click()选择全部歌曲For i = 0 To List2.ListCount - 1List2.Selected(i) = TrueNext iEnd SubPrivate Sub choose non e_Click()清除选择For i = 0 To List2.ListCount - 1List2.Selected(i) = FalseNext iEnd SubPrivate

37、Sub Comma nd1_Click()搜索歌曲并保存Ope n 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( 搜索完毕 , vbInformation, 提示 )Close #1Close #2End SubPrivate Sub Command2_Click()将选中歌曲添加到播放列表For i = 0 To List2.ListCount - 1

38、t = 0If List2.Selected(i) = True ThenFor j = 0 To Form1.List1.ListCount - 1n = Len(List2.List(i)If Right(Form1.List1.List(j), n) = List2.List(i) Then t = t + 1: Exit ForNextIf t = 0 ThenForm1.List1.AddItem (Form1.List1.ListCount + 1) & . & List2.List(i)Call Form1.WMP1.currentPlaylist.insertItem(Form1.WMP1.currentPlaylist.Count, Form1.WMP1.newMedia(List3.List(i)End IfEnd IfNext iFor i = 1 To List2.SelCountFor j = 0 To List2.ListCount - 1If List2.Selected(j) ThenList2.RemoveItem jList3.RemoveItem jExit ForEnd IfNext jNext is = MsgBox( 已添加到播放列表 , vbInformation, 提示 )End SubPrivate Sub Comm

温馨提示

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

评论

0/150

提交评论