VB里如何让WindowsMediaPlayer控件播放指定文件夹内音乐文件

是随机播放
2024-12-04 22:40:23
推荐回答(1个)
回答(1):

一个按钮,一个文本框用于输入文件夹地址(要正确输入,不要加引号),一个WMP,一个文件列表框
Dim i%

Private Sub Command1_Click()
On Error GoTo userCanceled
File1.Path = Text1.Text
If File1.ListCount < 2 Then Exit Sub
i = Int((File1.ListCount - 1) * Rnd)
File1.Selected(i) = True
WindowsMediaPlayer1.URL = File1.Path & "\" & File1.FileName
userCanceled:
End Sub

Private Sub Form_Load()
File1.Pattern = "*.AVI;*.MOV;*.DAT;*.MPG;*.WAV;*.MID;*.QT;*.MPEG;*.F4V" & _
";*.RM;*.RMVB;*.WMV;*.FLV;*.3GP;*.MP4;*.MP3;*.ASF;*.WMA;*.MKV;*.BC!"
End Sub

Private Sub WindowsMediaPlayer1_MediaChange(ByVal Item As Object)
WindowsMediaPlayer1.Controls.play
End Sub

Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
Select Case NewState
Case Is = wmppsMediaEnded
WindowsMediaPlayer1.Controls.play
i = Int((File1.ListCount - 1) * Rnd)
File1.Selected(i) = True
WindowsMediaPlayer1.URL = File1.Path & "\" & File1.FileName
End Select
End Sub