0

Microsoft.DirectX.AudioVideoPlaybackビデオ ファイルの長さを取得するために呼び出す関数を見つけました。

そのコードは次のとおりです。

`Private Function GetVideoInformation(ByVal videoFilePath As String) As VideoInfo
    Try
        If My.Computer.FileSystem.FileExists(videoFilePath) Then
            Dim videoToGetInfoOn As Microsoft.DirectX.AudioVideoPlayback.Video
            videoToGetInfoOn = New Microsoft.DirectX.AudioVideoPlayback.Video(videoFilePath)
            Dim atpf As Double = videoToGetInfoOn.AverageTimePerFrame
            Dim vidSize As New Size
            vidSize = videoToGetInfoOn.Size

        Dim thisVideoInfo As New VideoInfo
            thisVideoInfo.videoWidth = vidSize.Width
            thisVideoInfo.videoHeight = vidSize.Height
        thisVideoInfo.videoDuration = videoToGetInfoOn.Duration
        If videoToGetInfoOn.Duration > 0 Then
            defaultLength = videoToGetInfoOn.Duration
        End If

        If atpf > 0 Then
            thisVideoInfo.videoFps = 1 / atpf
        Else
            thisVideoInfo.videoFps = 0
        End If

        Return thisVideoInfo
    Else
        Throw New Exception("Video File Not Found" & vbCrLf & vbCrLf & videoFilePath)

        Return Nothing
    End If
   Catch ex as Exception
     msgbox(ex.message)
   End Try
End Function`

多くのビデオをチェックするためにこの関数を 2 秒に 1 回呼び出すタイマーがあり、アプリは最初の 10 本程度のビデオで正常に動作します。その後、投げます

"Error in application" 

代わりにメッセージ。

4

2 に答える 2

0

私はそれを働かせました。

コードには dispose メソッドが必要です。

最終的なコードは次のとおりです。

`Private Function GetVideoInformation(ByVal videoFilePath As String) As VideoInfo
    Try
      If My.Computer.FileSystem.FileExists(videoFilePath) Then
        Dim videoToGetInfoOn As Microsoft.DirectX.AudioVideoPlayback.Video
        videoToGetInfoOn = New Microsoft.DirectX.AudioVideoPlayback.Video(videoFilePath)
        Dim atpf As Double = videoToGetInfoOn.AverageTimePerFrame
        Dim vidSize As New Size
        vidSize = videoToGetInfoOn.Size

    Dim thisVideoInfo As New VideoInfo
        thisVideoInfo.videoWidth = vidSize.Width
        thisVideoInfo.videoHeight = vidSize.Height
    thisVideoInfo.videoDuration = videoToGetInfoOn.Duration
    If videoToGetInfoOn.Duration > 0 Then
        defaultLength = videoToGetInfoOn.Duration
    End If

    If atpf > 0 Then
        thisVideoInfo.videoFps = 1 / atpf
    Else
        thisVideoInfo.videoFps = 0
    End If

    videoToGetInfoOn.Dispose() 'this line here needed to be added
    Return thisVideoInfo
Else
    Throw New Exception("Video File Not Found" & vbCrLf & vbCrLf & videoFilePath)

    Return Nothing
End If
  Catch ex as Exception
     msgbox(ex.message)
  End Try
End Function`
于 2013-10-01T12:34:00.980 に答える