0

下面是我用来播放视频的代码。视频在面板上播放,但是当开始播放视频时,它只显示视频的一部分,如何将视频放在面板内?另外我怎样才能获得视频的默认大小(高度和宽度),以便我可以保持纵横比。

Private Sub movieWindow_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles movieWindow.DragDrop
    Dim file_names As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
    Dim result As String
    For Each file_name As String In file_names
        result = file_name.Substring(file_name.LastIndexOf("\") + 1)
        frmPlayList.playlist.Items.Add(result)
        frmPlayList.playlist2.Items.Add(file_name)
    Next file_name

    frmPlayList.playlist2.SelectedIndex = frmPlayList.playlist2.Items.Count - 1
    filename = frmPlayList.playlist2.SelectedIndex
    retVal = mciSendString("play movie", 0, 0, 0)
End Sub
4

1 回答 1

1

尝试使用这段代码自动调整您托管视频的面板上的电影大小。它还将保持正确的纵横比。(只需将面板的名称替换为“movieWindow”)

maxSize 是您希望视频的最大尺寸。它将被迫适应这个大小。

在发出“播放电影”命令之前调用 sub 权利。(编辑 3/20/2012 - 修正了变量名的错字)。

SizeVideoWindow(movieWindow.size)
dim retval as integer = mcisendstring("play movie", 0, 0, 0)

Private Sub SizeVideoWindow(maxSize as size)

    Dim ActualMovieSize As Size = getDefaultSize()
    Dim AspectRatio As Single = ActualMovieSize.Width / ActualMovieSize.Height

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

    Dim newWidth As Integer = maxSize.width
    Dim newHeight As Integer = newWidth \ AspectRatio

    If newHeight > maxSize.height Then

        newHeight = maxSize.height
        newWidth = 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, 0)

End Sub

Public Function getDefaultSize() As Size
    'Returns the default width, height the movie
    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
于 2012-03-16T04:00:10.410 回答