Movie's Length in Double without Plugin

  1. last week

    John C

    Dec 2 Pre-Release Testers

    How can I get a movie's time length in a double value without using a plugin? What would the approach look like?

  2. Julian S

    Dec 2 Pre-Release Testers, Xojo Pro UK
    1. Determine the file type the movie is saved in (as you didn't feel like giving us that info :))
    2. 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
    3. Work out where the movie length info is stored in that file format
    4. Read it and convert it into a double (if its not already)
  3. Norman P

    Dec 2 Pre-Release Testers, Xojo Pro under a bus

    Platform ?
    there may be an API on the respective OS that you could tap into that doesnt require the use of a plugin

  4. Michael D

    Dec 2 Pre-Release Testers, Xojo Pro

    Have you tried http://docs.xojo.com/MoviePlayer.Duration ?

  5. Christian S

    Dec 3 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    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:

     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

    As you see we also wait for the duration to be loaded asynchronously before we report it.

or Sign Up to reply!