如何使用 MCISendString 播放特定文件夹中的所有视频?

问题描述 投票:0回答:1

我需要一种方法来播放我保存在特定文件夹中的所有视频文件,并在播放后再次循环播放视频。

我已经在互联网上获得了

MCISendstring
基本教程中的一些代码,但只有一个视频正在使用我的文件夹路径播放,我认为我的代码有问题。任何帮助将不胜感激。

到目前为止,这是我的代码:

Public Class Form1

    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal _
        lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As _
             Integer, ByVal hwndCallback As Integer) As Integer

    Dim filename As String = "D:\Movielist\*.*"
    Dim filename As String = "D:\Movielist\Cronos.wmv"
    Dim retVal As Integer
    Dim playing As Boolean = False

    Private Sub Panel1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.SizeChanged
        If playing Then
            SizeVideoWindow(Panel1.Size)
        End If
    End Sub

    Private Sub SizeVideoWindow(ByVal maxSize As Size)
        Dim ActualMovieSize As Size = getDefaultSize()
        Dim AspectRatio As Single = CSng(ActualMovieSize.Width / ActualMovieSize.Height)

        Dim iLeft As Integer = 0
        Dim iTop As Integer = 0

        Dim newWidth As Integer = maxSize.width
        Dim newHeight As Integer = CInt(newWidth \ AspectRatio)

        If newHeight > maxSize.height Then
            newHeight = maxSize.height
            newWidth = CInt(newHeight * AspectRatio)
            iLeft = (maxSize.Width - newWidth) \ 2
        Else
            iTop = (maxSize.Height - newHeight) \ 2
        End If

        mciSendString("put movie window at " & iLeft & " " & iTop & " " & newWidth & " " & newHeight, "", 0, 0)

        mciSendString("play movie repeat", "", 0, 0)

        Console.ReadLine()
    End Sub

    Public Function getDefaultSize() As Size
        Dim c_Data As String = Space(128)
        mciSendString("where movie source", c_Data, 128, 0)
        Dim parts() As String = Split(c_Data, " ")

        Return New Size(CInt(parts(2)), CInt(parts(3)))
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        filename = Chr(34) & filename & Chr(34)
        retVal = mciSendString("open " & filename & " type mpegvideo alias movie parent " _
        & Panel1.Handle.ToInt32 & " style child", "", 0, 0)

        retVal = mciSendString("play movie", "", 0, 0)
        playing = True
        SizeVideoWindow(Panel1.Size)
    End Sub

End Class
vb.net video mcisendstring
1个回答
0
投票

发送整个项目,以便我可以提供帮助

© www.soinside.com 2019 - 2024. All rights reserved.