2012-01-07 14 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 
関連する問題