如何使用mciSendString调整视频大小

时间:2012-01-07 16:30:56

标签: vb.net mcisendstring

以下是我用来播放视频的代码。视频在面板上播放,但是当启动视频时,它只显示视频的一部分,我如何在面板内放置视频?另外,我如何获得视频的默认大小(高度和宽度),以便保持宽高比。

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

1 个答案:

答案 0 :(得分:1)

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

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

在发出“play movie”命令之前调用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