#تکه_کد
برای گرفتن مدت زمان یک ویدیو میتونید از کد زیر استفاده کنید :
`GetVideoDuration(File.Combine(Dir,Name))`
```Public Sub GetVideoDuration (path As String) As Long
Try
Dim mFile As JavaObject
mFile.InitializeNewInstance("java.io.File",Array(path))
Dim inputStream As JavaObject
inputStream.InitializeNewInstance("java.io.FileInputStream", _
Array(mFile.RunMethod("getAbsolutePath",Null)))
Dim mediaMetadataRetriever As JavaObject
mediaMetadataRetriever.InitializeNewInstance("android.media.MediaMetadataRetriever",Null)
mediaMetadataRetriever.RunMethod("setDataSource",Array(inputStream.RunMethod("getFD",Null)))
Dim duration As String = mediaMetadataRetriever.RunMethod("extractMetadata",Array(mediaMetadataRetriever.GetField("METADATA_KEY_DURATION")))
If duration="" Or duration="null" Then Return -1
Return duration
Catch
Log(LastException)
Return -1
End Try
End Sub```
برای گرفتن مدت زمان یک ویدیو میتونید از کد زیر استفاده کنید :
`GetVideoDuration(File.Combine(Dir,Name))`
```Public Sub GetVideoDuration (path As String) As Long
Try
Dim mFile As JavaObject
mFile.InitializeNewInstance("java.io.File",Array(path))
Dim inputStream As JavaObject
inputStream.InitializeNewInstance("java.io.FileInputStream", _
Array(mFile.RunMethod("getAbsolutePath",Null)))
Dim mediaMetadataRetriever As JavaObject
mediaMetadataRetriever.InitializeNewInstance("android.media.MediaMetadataRetriever",Null)
mediaMetadataRetriever.RunMethod("setDataSource",Array(inputStream.RunMethod("getFD",Null)))
Dim duration As String = mediaMetadataRetriever.RunMethod("extractMetadata",Array(mediaMetadataRetriever.GetField("METADATA_KEY_DURATION")))
If duration="" Or duration="null" Then Return -1
Return duration
Catch
Log(LastException)
Return -1
End Try
End Sub```