How can I get a movie’s time length in a double value without using a plugin? What would the approach look like?
- Determine the file type the movie is saved in (as you didn’t feel like giving us that info :))
- Read copious amounts of documentation on the file format of said video format, some of which could be locked behind NDA’s, patents or paywalls depending on the file format
- Work out where the movie length info is stored in that file format
- Read it and convert it into a double (if its not already)
Platform ?
there may be an API on the respective OS that you could tap into that doesnt require the use of a plugin
Without a plugin, well load it in a MoviePlayer and ask it for the length.
Be careful as loading may be asynchronously!
If you use MBS Xojo Plugins and here is an example for AVAssetMBS class:
[code] dim f as FolderItem = SpecialFolder.Desktop.Child(“test.m4v”)
dim a as AVAssetMBS = AVAssetmbs.assetWithFile(f)
if a = nil then
MsgBox “failed to read file at all”
Return
end if
// request duration property
a.loadValuesAsynchronouslyForKeys array(“duration”)
dim e as NSErrorMBS
dim Status as Integer = a.statusOfValueForKey(“duration”, e)
while status < a.AVKeyValueStatusLoaded
// wait for loading in background
status = a.statusOfValueForKey(“duration”, e)
wend
// got it?
if status <> a.AVKeyValueStatusLoaded then
MsgBox “Failed to load duration.”
if e <> nil then
MsgBox e.LocalizedDescription
end if
else
MsgBox str(a.duration.Seconds)+" seconds long."
end if[/code]
As you see we also wait for the duration to be loaded asynchronously before we report it.