我在vb中用的是wmp控件写一个播放器,遇到一个小问题。请问一首歌放完后自动放下一曲的代码怎么写?
2013-07-20
展开全部
WMP控件不能这样,你得加个定时器,半秒以后,播放下一首,在他结束本首歌以后,启动定时器!播放下一首了关闭定时器!这样用第三方过程来启动它的播放过程!
除非,你用了它带的播放列表list() Private Sub wmpTimer_Timer()
If WMP_All(0) Then '全循
If NowID < menuFile.Count - 1 Then
Call Play(NowID + 1)
Else
Play (0)
End If
ElseIf WMP_All(1) Then '单重放
Play (NowID)
ElseIf WMP_All(2) Then '顺放不重
If NowID < menuFile.Count - 1 Then
Call Play(NowID + 1)
End If
End If
wmpTimer.Enabled = False
End Sub Function Play(Index As Integer) As Boolean
Dim ii() As String
Dim jj() As String
If Not IsNull(WMP.Tag) And WMP.Tag <> "" Then ii = Split(WMP.Tag, "|")
Dim Path As String
On Error Resume Next
jj = Split(menuFile(Index).Tag, "|")
If UBound(jj) <> 3 Then Exit Function
If Dir(jj(3), vbNormal) <> "" Then
WMP.Controls.Stop
WMP.Tag = jj(0) + "|" + jj(1) + "|" + jj(2) + "|" + jj(3) '菜单index,歌曲名,歌曲ID,歌曲地址
menuFile(Val(ii(0))).Checked = False
menuFile(Val(jj(0))).Checked = True
Sbar.SimpleText = "正在播放影片(" + CStr(jj(0)) + ")" + CStr(jj(1)) + " 文件:" + CStr(jj(3))
WMP.URL = jj(3)
NowID = Index
WMP.Controls.Play
WMP.FullScreen = True
Else
WMP.Close
End If
End Function
Private Sub WMP_PlayStateChange(ByVal NewState As Long)
If NewState = 1 Then
If wmpTimer.Enabled = False Then wmpTimer.Enabled = True
End If
End Sub Function LoadMenu() As Boolean
On Error Resume Next
Call UnloadMenu
Dim rs As New ADODB.Recordset
Dim ind As Integer
Dim iij() As String
iij = Split(WMP.Tag, "|")
ind = 0
rs.Open "select * from wmpdata where State=true order by num", Conn, 1, 1
If Not rs.EOF Then
Do While Not rs.EOF
Load menuFile(ind)
With menuFile(ind)
.Caption = rs!name
.Enabled = rs!State
If UBound(iij) = 3 Then
If iij(1) = rs!name Then
.Checked = True
iij(0) = CStr(ind)
Else
.Checked = False
End If
End If
.Tag = CStr(ind) + "|" + CStr(rs!name) + "|" + CStr(rs!id) + "|" + CStr(rs!Path)
End With
rs.MoveNext
ind = ind + 1
Loop
WMP.Tag = Join(iij, "|")
Else menuFile(0).Caption = "没有影片"
menuFile(0).Enabled = False
menuFile(0).Checked = False
WMP.Tag = ""
WMP.Close
End If
rs.Close
Set rs = Nothing
End Function
Private Sub menuFile_Click(Index As Integer)
Call Play(Index)
End Sub
除非,你用了它带的播放列表list() Private Sub wmpTimer_Timer()
If WMP_All(0) Then '全循
If NowID < menuFile.Count - 1 Then
Call Play(NowID + 1)
Else
Play (0)
End If
ElseIf WMP_All(1) Then '单重放
Play (NowID)
ElseIf WMP_All(2) Then '顺放不重
If NowID < menuFile.Count - 1 Then
Call Play(NowID + 1)
End If
End If
wmpTimer.Enabled = False
End Sub Function Play(Index As Integer) As Boolean
Dim ii() As String
Dim jj() As String
If Not IsNull(WMP.Tag) And WMP.Tag <> "" Then ii = Split(WMP.Tag, "|")
Dim Path As String
On Error Resume Next
jj = Split(menuFile(Index).Tag, "|")
If UBound(jj) <> 3 Then Exit Function
If Dir(jj(3), vbNormal) <> "" Then
WMP.Controls.Stop
WMP.Tag = jj(0) + "|" + jj(1) + "|" + jj(2) + "|" + jj(3) '菜单index,歌曲名,歌曲ID,歌曲地址
menuFile(Val(ii(0))).Checked = False
menuFile(Val(jj(0))).Checked = True
Sbar.SimpleText = "正在播放影片(" + CStr(jj(0)) + ")" + CStr(jj(1)) + " 文件:" + CStr(jj(3))
WMP.URL = jj(3)
NowID = Index
WMP.Controls.Play
WMP.FullScreen = True
Else
WMP.Close
End If
End Function
Private Sub WMP_PlayStateChange(ByVal NewState As Long)
If NewState = 1 Then
If wmpTimer.Enabled = False Then wmpTimer.Enabled = True
End If
End Sub Function LoadMenu() As Boolean
On Error Resume Next
Call UnloadMenu
Dim rs As New ADODB.Recordset
Dim ind As Integer
Dim iij() As String
iij = Split(WMP.Tag, "|")
ind = 0
rs.Open "select * from wmpdata where State=true order by num", Conn, 1, 1
If Not rs.EOF Then
Do While Not rs.EOF
Load menuFile(ind)
With menuFile(ind)
.Caption = rs!name
.Enabled = rs!State
If UBound(iij) = 3 Then
If iij(1) = rs!name Then
.Checked = True
iij(0) = CStr(ind)
Else
.Checked = False
End If
End If
.Tag = CStr(ind) + "|" + CStr(rs!name) + "|" + CStr(rs!id) + "|" + CStr(rs!Path)
End With
rs.MoveNext
ind = ind + 1
Loop
WMP.Tag = Join(iij, "|")
Else menuFile(0).Caption = "没有影片"
menuFile(0).Enabled = False
menuFile(0).Checked = False
WMP.Tag = ""
WMP.Close
End If
rs.Close
Set rs = Nothing
End Function
Private Sub menuFile_Click(Index As Integer)
Call Play(Index)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询