2012-01-07 96 views
0

下面是我用來播放視頻的代碼。視頻在面板上播放,但是在開始播放視頻時,它只顯示視頻的一部分,我如何才能將視頻嵌入面板中?另外,如何獲得視頻的默認尺寸(高度和寬度),以便保持寬高比。如何使用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

試試這一點代碼來自動調整您承載視頻的面板上的電影大小。它也將保持正確的寬高比。 (只需將您面板的名稱替換爲「movieWindow」)

maxSize是您希望視頻的最大尺寸。它將被迫適應這個尺寸。

叫你發出「玩電影」的命令權之前子。 (編輯2012年3月20日 - 變量名稱上的固定拼寫錯誤)。

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 
相關問題