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

时间:2015-09-01 08:05:20

标签: vb.net video mcisendstring

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

我已经通过互联网从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

0 个答案:

没有答案