我正在开发用于播放视频文件的vb.net Windows应用程序。
我已经以这种方式在嵌入式资源中添加了视频文件:
项目 - >属性。然后选择“资源”选项卡。下一步选择“添加资源” - >“从现有文件”。
我能够在播放一个视频时取得成功,但我想播放多个视频。 (我在资源中还有5个视频)
我希望在第一个视频完成后运行另一个视频...
这是我播放单个视频的代码。
AxWindowsMediaPlayer1.uiMode = "full"
Dim FilePath = Path.Combine(Application.StartupPath, "video.wmv")
If (Not File.Exists(FilePath)) Then
File.WriteAllBytes(FilePath, My.Resources.My_video_file_name)
End If
AxWindowsMediaPlayer1.URL = FilePath
AxWindowsMediaPlayer1.Ctlcontrols.play()
我想通过创建播放列表或任何其他方式一个接一个地播放视频。
答案 0 :(得分:1)
n个文件的播放列表
Dim playlist As WMPLib.IWMPPlaylist = AxWindowsMediaPlayer1.playlistCollection.newPlaylist("Playlist")
playlist.appendItem(AxWindowsMediaPlayer1.newMedia(FilePath_1))
playlist.appendItem(AxWindowsMediaPlayer1.newMedia(FilePath_2))
...
playlist.appendItem(AxWindowsMediaPlayer1.newMedia(FilePath_n))
AxWindowsMediaPlayer1.currentPlaylist = playlist
AxWindowsMediaPlayer1.Ctlcontrols.play()
如果您不想使用播放列表,可以使用播放器的PlayStateChange事件来实现相同的效果。
Dim FilePath As String
Dim file_counter As Integer
Private Sub Start_Playlist(sender As Object, e As EventArgs) Handles Button1.Click
FilePath = Path.Combine(Application.StartupPath, "video1.mp4")
If (Not File.Exists(FilePath)) Then
File.WriteAllBytes(FilePath, My.Resources.video1)
End If
file_counter = 1
PlayVideo()
End Sub
Private Sub AxWindowsMediaPlayer1_PlayStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If (AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded) Then
Select Case file_counter
Case 1
FilePath = Path.Combine(Application.StartupPath, "video2.mp4")
If (Not File.Exists(FilePath)) Then
File.WriteAllBytes(FilePath, My.Resources.video2)
End If
Case 2
FilePath = Path.Combine(Application.StartupPath, "video3.mp4")
If (Not File.Exists(FilePath)) Then
File.WriteAllBytes(FilePath, My.Resources.video3)
End If
...
Case Else
FilePath = ""
End Select
If (Not FilePath.Equals("")) Then
file_counter += 1
Me.BeginInvoke(New MethodInvoker(AddressOf PlayVideo))
End If
End If
End Sub
Private Sub PlayVideo()
AxWindowsMediaPlayer1.URL = FilePath
AxWindowsMediaPlayer1.Ctlcontrols.play()
End Sub