




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、音乐播放器设计一、先来欣赏一下本音乐播放器的最终效果吧:设计思路很简单,即下面两个窗体的设计。二、主窗体(form1)界面设计如下:主窗体(form1)代码如下:Dim t As Integer, a As BooleanDim p As Integer, b, w As Boolean, onePrivate Sub allclear_Click()'清空播放列表List1.ClearWMP1.currentPlaylist.ClearForm1.Caption = "无任何曲目"End SubPrivate Sub allloop_Click()'全部循
2、环播放Timer3.Enabled = Falseallloop.Checked = Trueoneloop.Checked = Falserand.Checked = Falserule.Checked = FalseCall WMP1.settings.setMode("loop", True)End SubPrivate Sub Form_Load()'初始化Form1.Height = 7800w = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Che
3、cked = TrueLabel2.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:fi
4、lepath.txt" For Input As #1Open "C:music.txt" For Input As #2Do While Not EOF(1) Input #1, X Input #2, Y If Dir(X) <> "" Then List1.AddItem (List1.ListCount + 1) & "." & Y Call WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(
5、X) End IfLoopClose #1Close #2'初始化If List1.ListCount <> 0 Then List1.Selected(0) = TruePicture3(0).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).
6、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, 52Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23a = FalseCall WMP1.settings.
7、setMode("shuffle", False) '初始设置为顺序播放Label1.Caption = Mid(List1.List(0), InStr(List1.List(0), ".") + 1)sd1.Value = 50 '音量设置为50%End SubPrivate Sub List1_DblClick()'双击播放Call WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex)a = Truet = 1Picture3(0).PaintPi
8、cture 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 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)'
9、伸缩播放列表If X > List1.Width - 430 And X < List1.Width - 330 ThenList1.MousePointer = 9ElseList1.MousePointer = 0End IfIf w = True 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 Su
10、bPrivate Sub List1_Scroll()List1.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)'播
11、放进度控制If WMP1.playState = wmppsPlaying ThenWMP1.Controls.currentPosition = WMP1.currentMedia.duration * X / 233Pc13.ClsPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - X, 0, 233, 17End IfEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)'切换图片I
12、f t = 0 Then Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 Then Picture3(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).PaintPicture Picture2(3).Pict
13、ure, 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, 52End SubPrivate Sub Picture10_Click()'打开搜索窗体Form2.ShowEnd SubPrivate Sub Picture11_Click()'设置静音sd1.Value = 0Picture11.
14、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, Y As Single)If Index = 0 ThenIf a = True Then Call WMP1.Controls.pause '播放 Else Call WMP1.Controls.play '暂停End IfEnd IfIf Index
15、 = 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&
16、quot;CommonDialog1.InitDir = "D:"CommonDialog1.ShowOpenfname = CommonDialog1.FileTitlegname = CommonDialog1.FileNameIf fname <> "" Then n = Len(fname) For i = 0 To List1.ListCount - 1 If Right(List1.List(i), n - 4) = Left(fname, n - 4) Then Call WMP1.Controls.playItem(WMP1.
17、currentPlaylist.Item(i) '播放添加后的歌曲 Timer1.Enabled = True List1.ListIndex = i Exit Sub End If Next List1.AddItem (List1.ListCount + 1) & "." & Left(fname, n - 4) '歌曲无重复则添加到播放列表,否则不再添加 Call WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(gname) List1.
18、ListIndex = List1.ListCount - 1 List1.Selected(i) = True Call WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex) Timer1.Enabled = TrueEnd IfEnd IfEnd SubPrivate Sub Picture3_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)'根据不同情况切换图片,实现动态按
19、钮功能If Index = 0 ThenIf t = 0 Then If X < 6 Or X > 80 Or Y < 6 Or Y > 48 Then Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52 Else Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 228, 0, 114, 52 End IfEnd IfIf t = 1 Then If X < 6 Or X > 80 Or
20、Y < 6 Or Y > 48 Then Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52 Else Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 228, 0, 114, 52End IfEnd IfEnd IfIf Index = 1 Then If X < 6 Or X > 55 Or Y < 6 Or Y > 48 Then Picture3(1).PaintPicture P
21、icture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52 Else Picture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 60, 0, 60, 52 End IfEnd IfIf Index = 2 Then If X < 6 Or X > 65 Or Y < 6 Or Y > 48 Then Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52 Else Picture3(2)
22、.PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 83, 0, 83, 52 End IfEnd IfIf Index = 3 Then If X < 6 Or X > 65 Or Y < 6 Or Y > 48 Then Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52 Else Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 166, 0, 83, 52
23、 End IfEnd IfIf Index = 4 Then If X < 6 Or X > 55 Or Y < 6 Or Y > 48 Then Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52 Else Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 120, 0, 60, 52 End IfEnd IfEnd SubPrivate Sub Picture4_MouseMove(Button As I
24、nteger, Shift As Integer, X As Single, Y As Single)'图片切换'If t = 0 Then Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 Then Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfPicture3(1).PaintPicture Picture2(2).Picture, 0
25、, 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, 83, 52, 0, 0, 83, 52End SubPrivate Sub Picture5_Click()'显示或隐藏播放列表If b = 0 T
26、henForm1.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()'关闭窗体之前保存播放列表数据O
27、pen "C:filepath.txt" For Output As #1Open "C:music.txt" For Output As #2 For i = 0 To List1.ListCount - 1 n = InStr(List1.List(i), ".") Write #1, WMP1.currentPlaylist.Item(i).sourceURL Write #2, Mid(List1.List(i), n + 1) NextClose #1Close #2EndEnd SubPrivate Sub Picture
28、8_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)'播放模式设置菜单PopupMenu menusetEnd SubPrivate Sub Picture9_Click()'删除菜单PopupMenu gclearEnd SubPrivate Sub rand_Click()'随机播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Truerule.Checke
29、d = FalseCall WMP1.settings.setMode("shuffle", True)End SubPrivate Sub rule_Click()'顺序播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Checked = TrueCall WMP1.settings.setMode("shuffle", False)End SubPrivate Sub sd1_Change()'音
30、量控制条WMP1.settings.volume = sd1.Valuesd1.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,
31、 23, 0, 0, 19, 23End IfEnd SubPrivate Sub select_Click()'删除选中项For i = 0 To List1.ListCount - 1 If List1.Selected(i) Then List1.RemoveItem (i) m = i Call WMP1.currentPlaylist.RemoveItem(WMP1.currentPlaylist.Item(i) Exit For End IfNext For i = 0 To List1.ListCount - 1 n = InStr(List1.List(i), &quo
32、t;.") 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.Count <> 0
33、 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 = 1 Picture3(0).ToolTipText = "播放"ElseLabel2.Caption = "00:00"Picture3(0).PaintPicture Picture2(0).Picture, 0,
34、0, 114, 52, 0, 0, 114, 52 a = False t = 0 Picture3(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
35、 - 233 * WMP1.Controls.currentPosition / 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.
36、Caption = "正在播放" + WMP1.currentMedia.getItemInfo("title")End IfEnd IfEnd SubPrivate 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_OpenSt
37、ateChange(ByVal NewState As Long)n = 0If p = 0 ThenFor i = 0 To List1.ListCount - 1If WMP1.currentPlaylist.Item(i).getItemInfo("title") <> WMP1.currentMedia.getItemInfo("title") Then n = n + 1 Else Exit For End IfNextone = n Label1.Caption = Mid(List1.List(n), InStr(List1.L
38、ist(n), ".") + 1) '显示正在播放的曲目 List1.Selected(n) = True End IfLabel3.Caption = WMP1.currentMedia.durationString '显示歌曲总长End Sub三、副窗体(form1)界面设计如下:说明:该窗体用于搜索电脑已有歌曲(本音乐播放器的特色所在)副窗体(form1)代码如下:Dim n As Integer, temp(10000) As String, m As IntegerPrivate Sub choose_Click()'选择全部歌曲For i
39、 = 0 To List2.ListCount - 1 List2.Selected(i) = TrueNext iEnd SubPrivate Sub choosenone_Click()'清除选择For i = 0 To List2.ListCount - 1 List2.Selected(i) = FalseNext iEnd SubPrivate Sub Command1_Click()'搜索歌曲并保存Open "C:searchresult.txt" For Output As #1Open "C:geresult.txt" F
40、or 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 t = 0 If List2.Selected(i) = True Then For j = 0 To Form1.List1
41、.ListCount - 1 n = Len(List2.List(i) If Right(Form1.List1.List(j), n) = List2.List(i) Then t = t + 1: Exit For Next If t = 0 Then Form1.List1.AddItem (Form1.List1.ListCount + 1) & "." & List2.List(i) Call Form1.WMP1.currentPlaylist.insertItem(Form1.WMP1.currentPlaylist.Count, Form1
42、.WMP1.newMedia(List3.List(i) End If End IfNext iFor i = 1 To List2.SelCountFor j = 0 To List2.ListCount - 1 If List2.Selected(j) Then List2.RemoveItem j List3.RemoveItem j Exit For End IfNext jNext is = MsgBox("已添加到播放列表", vbInformation, "提示")End SubPrivate Sub Command3_Click()'读取文件(上次最后一次搜索结果)If Dir("C:searchresult.txt") <> "" And Dir("C:geresult.txt") <> "" ThenOpen "C:searchresult
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 行政管理对城市发展的影响试题及答案
- 清远2025年清远市招聘6名事业编制高层次人才笔试历年参考题库附带答案详解
- 山东2025年山东开放大学公开招聘11人笔试历年参考题库附带答案详解
- 行政管理的协调机制与实践试题及答案
- 2025年甘肃省中材科技(酒泉)风电叶片有限公司招聘100人笔试参考题库附带答案详解
- 行政管理学考试的注意事项试题及答案
- 水利水电工程考试实践试题及答案
- BIM技术在建筑项目设计变更管理中的应用与挑战报告
- 工程项目管理资源评估技巧试题及答案
- 2024年水利水电工程考试知识点提炼试题及答案
- 《不朽的贝尼尼雕塑》课件
- 建筑工程抗浮技术标准JGJ476-2019
- 云计算标准体系研究报告
- 生产线技改后效果对比
- 五年级美国大联盟计算和几何专题讲义教师版(含题目翻译答案解析)
- 学院本科教学工作审核评估支撑材料目录
- 人教版小学语文一年级到六年级课本古诗
- 全国优质课一等奖中职中专计算机专业教师教学设计和说课大赛《Premiere视频制作初体验》说课课件
- 农村供水建设和运维存在的问题及解决措施
- 铁路货车空重车自动调整装置原理的作用课件
- 汽轮机DEH简介和SGC顺控启动
评论
0/150
提交评论