Dim i As Integer
Dim pa, a, k As String
Private Sub Form_Load()
Randomize
End Sub
Private Sub btnOpen_Click()
Dim song As String
With CommonDialog1
.FileName = “”
.Filter = “.mp4;.avi;.wmv;.mov|.mp4;.avi;.wmv;.mov”
.Flags = 512
.ShowOpen
song = .FileName
End With
If song = “” Then Exit Sub
a = “”
For i = Len(song) To 1 Step -1
k = Mid(song, i, 1)
If k = " " Then '多首歌的分隔符
txtVideoFileList.AddItem a
a = “”
ElseIf k = “” Then '一首歌时歌名与路径的分隔符
txtVideoFileList.AddItem a
pa = Left(song, i)
Exit Sub
Else
a = k & a
End If
Next i
End Sub
Private Sub btnPlay_Click()
MediaPlayer1.URL = pa & txtVideoFileList.Text '播放
End Sub
Private Sub btnStop_Click()
MediaPlayer1.Controls.stop '停止
End Sub
Private Sub btnPause_Click()
MediaPlayer1.Controls.pause '暂停
End Sub
Private Sub btnResume_Click()
MediaPlayer1.Controls.play '继续
End Sub
Private Sub btnRandom_Click()
Dim selectedIndex As Integer
selectedIndex = Int(Rnd * txtVideoFileList.ListCount)
txtVideoFileList.ListIndex = selectedIndex
MediaPlayer1.URL = txtVideoFileList.List(selectedIndex)
End Sub
Private Sub btnSequence_Click()
If txtVideoFileList.ListIndex <> -1 Then
If txtVideoFileList.ListIndex < txtVideoFileList.ListCount - 1 Then
txtVideoFileList.ListIndex = txtVideoFileList.ListIndex + 1
Else
txtVideoFileList.ListIndex = 0
End If
MediaPlayer1.URL = txtVideoFileList.List(txtVideoFileList.ListIndex)
End If
End Sub
Private Sub btnLoop_Click()
MediaPlayer1.settings.setMode “loop”, True '循环播放
MediaPlayer1.Controls.play
End Sub
Private Sub btnNext_Click()
If txtVideoFileList.ListIndex < txtVideoFileList.ListCount - 1 Then
txtVideoFileList.ListIndex = txtVideoFileList.ListIndex + 1
End If
MediaPlayer1.URL = txtVideoFileList.List(txtVideoFileList.ListIndex)
End Sub
Private Sub btnPrevious_Click()
If txtVideoFileList.ListIndex > 0 Then
txtVideoFileList.ListIndex = txtVideoFileList.ListIndex - 1
End If
MediaPlayer1.URL = txtVideoFileList.List(txtVideoFileList.ListIndex)
End Sub
Private Function GetIndex(MyArray() As String, MyString As String) As Integer
'查找字符串在字符串数组中的索引值
Dim i As Integer
For i = LBound(MyArray) To UBound(MyArray)
If MyArray(i) = MyString Then
GetIndex = i
Exit Function
End If
Next
End Function