2012-01-07 2 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 
관련 문제