【问题标题】:How to play videos one by one videos in vb.net from embedded resource如何在 vb.net 中从嵌入式资源中一一播放视频
【发布时间】:2016-01-12 18:36:59
【问题描述】:

我正在开发用于播放视频文件的 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()

我想通过创建播放列表或任何其他方式一个接一个地播放视频。

【问题讨论】:

    标签: vb.net video


    【解决方案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
    

    【讨论】:

    • 非常感谢,它运行流畅...但我有视频大小的问题...我有 5 个大小为 1 GB 的视频...它给出了一个错误 - >无法写入输出文件“C:\Users\Server\Desktop\Temp\VideoToEXE\playerwithvideo\EmbdedVideoInexe\EmbdedVideoInexe\obj\x86\Debug\EmbdedVideoInexe.exe”:没有足够的存储空间来完成此操作。 EmbdedVideoInexe 在这我能做什么...
    • 什么时候出现错误?你的系统规格是什么?
    • 它适用于高达 400 MB 的视频...当我再添加一个 180 MB 的视频时,它开始显示上述错误...我有 i3 处理器和 8 GB RAM 和 Windows 7 Professional.. .
    • 将视频添加到资源中出现错误?
    • 硬盘空间是否足够?您可以尝试将目标框架和 cpu 更改为 4.5.2 和 x64。那是我的设置。如果这不起作用,恐怕我无法帮助你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多