音乐播放器VB编程源代码Word格式.docx
《音乐播放器VB编程源代码Word格式.docx》由会员分享,可在线阅读,更多相关《音乐播放器VB编程源代码Word格式.docx(20页珍藏版)》请在冰豆网上搜索。
![音乐播放器VB编程源代码Word格式.docx](https://file1.bdocx.com/fileroot1/2023-1/31/6fdacd08-af11-450b-8301-5b47e3784838/6fdacd08-af11-450b-8301-5b47e37848381.gif)
PrivateSubForm_Load()
初始化
Form1.Height=7800
w=False
allloop.Checked=False
rule.Checked=True
Label2.Caption="
00:
00"
第一次打开时创建文件
IfDir("
filepath.text"
)="
"
AndDir("
C:
\music.txt"
Then
Open"
\filepath.txt"
ForOutputAs#1
Close#1
ForOutputAs#2
Close#2
EndIf
读取文件
ForInputAs#1
ForInputAs#2
DoWhileNotEOF
(1)
Input#1,X
Input#2,Y
IfDir(X)<
>
"
List1.AddItem(List1.ListCount+1)&
."
&
Y
CallWMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count,WMP1.newMedia(X))
EndIf
Loop
IfList1.ListCount<
0ThenList1.Selected(0)=True
Picture3(0).Width=114
Picture3(0).Height=52
Picture3(0).PaintPicturePicture2(0).Picture,0,0,114,52,0,0,114,52
Picture3
(1).PaintPicturePicture2
(2).Picture,0,0,60,52,0,0,60,52
Picture3
(2).PaintPicturePicture2(3).Picture,0,0,83,52,0,0,83,52
Picture3(4).PaintPicturePicture2(5).Picture,0,0,60,52,0,0,60,52
Picture3(3).PaintPicturePicture2(4).Picture,0,0,83,52,0,0,83,52
Picture11.PaintPicturePicture12.Picture,0,0,19,23,0,0,19,23
a=False
shuffle"
False)'
初始设置为顺序播放
Label1.Caption=Mid(List1.List(0),InStr(List1.List(0),"
)+1)
sd1.Value=50'
音量设置为50%
PrivateSubList1_DblClick()
双击播放
CallWMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex))
a=True
t=1
Picture3(0).PaintPicturePicture2
(1).Picture,0,0,114,52,0,0,114,52
PrivateSubList1_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfX>
List1.Width-430Then
w=True
PrivateSubList1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
伸缩播放列表
List1.Width-430AndX<
List1.Width-330Then
List1.MousePointer=9
Else
List1.MousePointer=0
Ifw=TrueAndX>
1500AndX<
5800Then
List1.Width=X
PrivateSubList1_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
PrivateSubList1_Scroll()
PrivateSuboneloop_Click()
单曲循环
oneloop.Checked=True
Timer3.Enabled=True
PrivateSubPc13_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
播放进度控制
IfWMP1.playState=wmppsPlayingThen
WMP1.Controls.currentPosition=WMP1.currentMedia.duration*X/233
Pc13.Cls
Pc13.PaintPicturePc14.Picture,0,0,233,17,234-X,0,233,17
PrivateSubPicture1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
切换图片
Ift=0Then
Picture3(0).PaintPicturePicture2(0).Picture,0,0,114,52,0,0,114,52
Ift=1Then
Picture3(0).PaintPicturePicture2
(1).Picture,0,0,114,52,0,0,114,52
PrivateSubPicture10_Click()
打开搜索窗体
Form2.Show
PrivateSubPicture11_Click()
设置静音
sd1.Value=0
Picture11.PaintPicturePicture12.Picture,0,0,19,23,38,0,19,23
PrivateSubPicture3_MouseDown(IndexAsInteger,ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfIndex=0Then
Ifa=TrueThen
CallWMP1.Controls.pause'
播放
Else
CallWMP1.Controls.play'
暂停
IfIndex=3Then
p=1
CallWMP1.Controls.Next'
下一首
p=0
IfIndex=2Then
CallWMP1.Controls.previous'
上一首
IfIndex=4ThenCallWMP1.Controls.stop'
停止播放
打开音乐文件
IfIndex=1Then
CommonDialog1.DialogTitle="
打开音乐文件"
CommonDialog1.Filter="
mp3|*.mp3|wma|*.wma"
CommonDialog1.InitDir="
D:
\"
CommonDialog1.ShowOpen
fname=CommonDialog1.FileTitle
gname=CommonDialog1.FileName
Iffname<
n=Len(fname)
Fori=0ToList1.ListCount-1
IfRight(List1.List(i),n-4)=Left(fname,n-4)Then
CallWMP1.Controls.playItem(WMP1.currentPlaylist.Item(i))'
播放添加后的歌曲
Timer1.Enabled=True
List1.ListIndex=i
ExitSub
Next
Left(fname,n-4)'
歌曲无重复则添加到播放列表,否则不再添加
CallWMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count,WMP1.newMedia(gname))
List1.ListIndex=List1.ListCount-1
List1.Selected(i)=True
CallWMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex))
PrivateSubPicture3_MouseMove(IndexAsInteger,ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
根据不同情况切换图片,实现动态按钮功能
IfX<
6OrX>
80OrY<
6OrY>
48Then
Picture3(0).PaintPicturePicture2(0).Picture,0,0,114,52,228,0,114,52
Picture3(0).PaintPicturePicture2
(1).Picture,0,0,114,52,228,0,114,52
55OrY<
Picture3
(1).PaintPicturePicture2
(2).Picture,0,0,60,52,0,0,60,52
Picture3
(1).PaintPicturePicture2
(2).Picture,0,0,60,52,60,0,60,52
65OrY<
Picture3
(2).PaintPicturePicture2(3).Picture,0,0,83,52,0,0,83,52
Picture3
(2).PaintPicturePicture2(3).Picture,0,0,83,52,83,0,83,52
Picture3(3).PaintPicturePicture2(4).Picture,0,0,83,52,0,0,83,52
Picture3(3).PaintPicturePicture2(4).Picture,0,0,83,52,166,0,83,52
IfIndex=4Then
Picture3(4).PaintPicturePicture2(5).Picture,0,0,60,52,0,0,60,52
Picture3(4).PaintPicturePicture2(5).Picture,0,0,60,52,120,0,60,52
PrivateSubPicture4_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
图片切换'
PrivateSubPicture5_Click()
显示或隐藏播放列表
Ifb=0Then
Form1.Width=5940
Form1.Height=3900
b=1
Picture5.ToolTipText="
显示播放列表"
b=0
隐藏播放列表"
PrivateSubPicture6_Click()
最小化窗体
Form1.WindowState=1
PrivateSubPicture7_Click()
关闭窗体之前保存播放列表数据
n=InStr(List1.List(i),"
)
Write#1,WMP1.currentPlaylist.Item(i).sourceURL
Write#2,Mid(List1.List(i),n+1)
End
PrivateSubPicture8_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
播放模式设置菜单
PopupMenumenuset
PrivateSubPicture9_Click()
删除菜单
PopupMenugclear
PrivateSubrand_Click()
随机播放
rand.Checked=True
PrivateSubrule_Click()
顺序播放
False)
PrivateSubsd1_Change()
音量控制条
WMP1.settings.volume=sd1.Value
sd1.ToolTipText="
音量"
sd1.Value&
%'
Ifsd1.Value=0Thensd1.ToolTipText="
静音"
Ifsd1.Value=100Thensd1.ToolTipText="
最大音量"
Ifsd1.Value<
0Then
PrivateSubselect_Click()
删除选中项
Fori=0ToList1.ListCount-1
IfList1.Selected(i)Then
List1.RemoveItem(i)
m=i
CallWMP1.currentPlaylist.RemoveItem(WMP1.currentPlaylist.Item(i))
ExitFor
Next
List1.List(i)=(i+1)&
Mid(List1.List(i),n+1)
IfList1.ListCount=0ThenExitSub
IfList1.ListCount=mThen
List1.Selected(m-1)=True
List1.Selected(m)=True
PrivateSubTimer1_Timer()
更新播放动态
IfWMP1.currentPlaylist.Count<
IfWMP1.playState=3Then
Label2.Caption=WMP1.Controls.currentPositionString
a=True
t=1
Picture3(0).ToolTipText="
播放"
a=False