




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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年入團考試重要反饋與試題與答案
- 2025年護士考試專業道德試題及答案
- 企業財務報表的編制要求試題及答案
- 醫療大數據助力精準治療改善患者預后
- 無人機整體性能考題與答案
- 2025年醫院消化內科年度工作計劃
- 水資源應急調度模型-洞察分析
- DB51-T 3000-2023 退役軍人服務站建設與運行管理規范
- 神經指南:中國成人失眠診斷與治療指南(2017版)
- 代理商合作條件說明
- DB11-T 1952-2022 地理國情監測技術規程
- GB/T 15843.2-2024網絡安全技術實體鑒別第2部分:采用鑒別式加密的機制
- 完整版:美制螺紋尺寸對照表(牙數、牙高、螺距、小徑、中徑外徑、鉆孔)
- 陪診服務協議
- 2023年廣東深圳中考滿分作文《把學到的東西用起來真有意義》
- 2024年湖南省衡陽八中教育集團直選生數學模擬試卷+
評論
0/150
提交評論