【高分】VB中的Windowsmediaplayer控件,如何实现自动播放下一个视频文件
我建立了一个form,在程序data目录下有3个avi:1.avi、2.avi、3.avi,form中加载一个wmp控件,url属性为1.avi,写入什么代码,当1.av...
我建立了一个form,在程序data目录下有3个avi:1.avi、2.avi、3.avi,form中加载一个wmp控件,url属性为1.avi,写入什么代码,当1.avi播放完毕后,开始播放2.avi,2.avi播放完毕后播放3.avi,3.avi播放完毕后弹出msgbox提示播放完毕呢?
VB是VB6.0企业版,WMP的版本是10,也就是Windows Media Player 10
3L的朋友,能否提供一下示例代码?分数不是问题,可以追加到250分 展开
VB是VB6.0企业版,WMP的版本是10,也就是Windows Media Player 10
3L的朋友,能否提供一下示例代码?分数不是问题,可以追加到250分 展开
5个回答
展开全部
你看看这个代码:
Dim b As Integer
Private Sub Command1_Click()
a = 0: b = 0
p = App.Path + "\data\"
If Dir(p & "*.avi") = "" Then MsgBox "没有avi文件": Exit Sub
Dim filenames() As String '读取目录下的avi文件
Dim f As String
n = 0
f = Dir(p & "*.avi")
Do While f <> ""
ReDim Preserve filenames(n)
filenames(n) = f
f = Dir
n = n + 1
Loop
Set sPlaylist = WindowsMediaPlayer1.playlistCollection.newPlaylist("avi") '建立新播放列表avi
WindowsMediaPlayer1.currentPlaylist = sPlaylist
For i = 0 To n - 1
Set sMedia = WindowsMediaPlayer1.mediaCollection.Add(p & filenames(i)) '将文件加入到播放列表中
WindowsMediaPlayer1.currentPlaylist.insertItem (WindowsMediaPlayer1.currentPlaylist.Count), sMedia '添加播放列表项
Next
WindowsMediaPlayer1.Controls.play '开始播放
End Sub
Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
If NewState = 10 Then b = b + 1 '当播放状态为准备就绪的判断方法
If b = 2 Then MsgBox "播放结束"
End Sub
Dim b As Integer
Private Sub Command1_Click()
a = 0: b = 0
p = App.Path + "\data\"
If Dir(p & "*.avi") = "" Then MsgBox "没有avi文件": Exit Sub
Dim filenames() As String '读取目录下的avi文件
Dim f As String
n = 0
f = Dir(p & "*.avi")
Do While f <> ""
ReDim Preserve filenames(n)
filenames(n) = f
f = Dir
n = n + 1
Loop
Set sPlaylist = WindowsMediaPlayer1.playlistCollection.newPlaylist("avi") '建立新播放列表avi
WindowsMediaPlayer1.currentPlaylist = sPlaylist
For i = 0 To n - 1
Set sMedia = WindowsMediaPlayer1.mediaCollection.Add(p & filenames(i)) '将文件加入到播放列表中
WindowsMediaPlayer1.currentPlaylist.insertItem (WindowsMediaPlayer1.currentPlaylist.Count), sMedia '添加播放列表项
Next
WindowsMediaPlayer1.Controls.play '开始播放
End Sub
Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
If NewState = 10 Then b = b + 1 '当播放状态为准备就绪的判断方法
If b = 2 Then MsgBox "播放结束"
End Sub
展开全部
最简单有效的方法是用timer控件测试是否停止播放。
以下的方法都是针对外置播放列表的使用。如果想用wmp内置播放列表可以使用 mafan8 的方法。
这是timer的方法。只是简单,但是并不推荐。
Private Sub Timer1_Timer()
If wmp.playState = 1 Then
mIndex = mIndex + 1
If mIndex = 4 Then
mIndex = 1
MsgBox "播放完毕!"
Else
wmp.URL = mList(mIndex)
wmp.Controls.play
End If
End If
End Sub
以下方法比较推荐,使用PlayStateChange事件,手上没avi,以mp3为例。
Dim mList() As String
Dim mIndex As Long
Dim IsPlayNext As Boolean
Private Sub cmdPlay_Click()
wmp.URL = mList(mIndex)
End Sub
Private Sub cmdStop_Click()
wmp.Controls.stop
End Sub
Private Sub Form_Load()
Dim l As Long
ReDim mList(1 To 3)
For l = 1 To 3
mList(l) = App.Path & "\" & l & ".mp3"
Next
mIndex = 1
End Sub
Private Sub wmp_PlayStateChange(ByVal NewState As Long)
If NewState = 8 Then
mIndex = mIndex + 1
If mIndex = 4 Then
mIndex = 1
MsgBox "播放完毕!"
Else
IsPlayNext = True
End If
End If
If NewState = 1 And IsPlayNext Then
wmp.URL = mList(mIndex)
End If
If NewState = 3 Then IsPlayNext = False
End Sub
以下的方法都是针对外置播放列表的使用。如果想用wmp内置播放列表可以使用 mafan8 的方法。
这是timer的方法。只是简单,但是并不推荐。
Private Sub Timer1_Timer()
If wmp.playState = 1 Then
mIndex = mIndex + 1
If mIndex = 4 Then
mIndex = 1
MsgBox "播放完毕!"
Else
wmp.URL = mList(mIndex)
wmp.Controls.play
End If
End If
End Sub
以下方法比较推荐,使用PlayStateChange事件,手上没avi,以mp3为例。
Dim mList() As String
Dim mIndex As Long
Dim IsPlayNext As Boolean
Private Sub cmdPlay_Click()
wmp.URL = mList(mIndex)
End Sub
Private Sub cmdStop_Click()
wmp.Controls.stop
End Sub
Private Sub Form_Load()
Dim l As Long
ReDim mList(1 To 3)
For l = 1 To 3
mList(l) = App.Path & "\" & l & ".mp3"
Next
mIndex = 1
End Sub
Private Sub wmp_PlayStateChange(ByVal NewState As Long)
If NewState = 8 Then
mIndex = mIndex + 1
If mIndex = 4 Then
mIndex = 1
MsgBox "播放完毕!"
Else
IsPlayNext = True
End If
End If
If NewState = 1 And IsPlayNext Then
wmp.URL = mList(mIndex)
End If
If NewState = 3 Then IsPlayNext = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
窗体上添加一个WindowsMediaPlayer1和一个Command1
Private Sub Command1_Click()
Dim listCollection As IWMPPlaylistCollection
Dim list As IWMPPlaylist
Dim wmpMedia As IWMPMedia
Dim name As String
Dim songs(2) As String
Dim i As Integer
name = "test"
songs(0) = App.Path & "\data\1.avi"
songs(1) = App.Path & "\data\2.avi"
songs(2) = App.Path & "\data\3.avi"
Set listCollection = WindowsMediaPlayer1.playlistCollection
Set list = listCollection.newPlaylist(name)
WindowsMediaPlayer1.currentPlaylist = list
For i = 0 To UBound(songs)
Set wmpMedia = WindowsMediaPlayer1.newMedia(songs(i))
WindowsMediaPlayer1.currentPlaylist.appendItem wmpMedia
Next
WindowsMediaPlayer1.Controls.play
End Sub
Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
Select Case NewState
Case 8
If WindowsMediaPlayer1.currentMedia.name = "3" Then
MsgBox "播放完毕"
End If
End Select
End Sub
Private Sub Command1_Click()
Dim listCollection As IWMPPlaylistCollection
Dim list As IWMPPlaylist
Dim wmpMedia As IWMPMedia
Dim name As String
Dim songs(2) As String
Dim i As Integer
name = "test"
songs(0) = App.Path & "\data\1.avi"
songs(1) = App.Path & "\data\2.avi"
songs(2) = App.Path & "\data\3.avi"
Set listCollection = WindowsMediaPlayer1.playlistCollection
Set list = listCollection.newPlaylist(name)
WindowsMediaPlayer1.currentPlaylist = list
For i = 0 To UBound(songs)
Set wmpMedia = WindowsMediaPlayer1.newMedia(songs(i))
WindowsMediaPlayer1.currentPlaylist.appendItem wmpMedia
Next
WindowsMediaPlayer1.Controls.play
End Sub
Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
Select Case NewState
Case 8
If WindowsMediaPlayer1.currentMedia.name = "3" Then
MsgBox "播放完毕"
End If
End Select
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先你要确定你用的是哪个版本的VB的哈,还有那个控件的版本,才好给你的哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我也在解决这个问题,可以共同探讨下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询