Android Question How to get audio file time duration?

Discussion in 'Android Questions' started by Massy, Jun 2, 2015.

  1. Massy

    Massy Member Licensed User

    Hello, I'm using Audio library with Erel example: http://www.b4x.com/android/forum/threads/audio-library-v1-5-new-audiostreamer-object.30550/
    now I want to read the time duration of the recorded file, I'm using this code but something is not working and I always get the error: setDataSource not matched. This is my code:

    Code:
    Dim jo As JavaObject
         jo.InitializeNewInstance(
    "android.media.MediaMetadataRetriever"Null)
         
    Dim m As Map
         m.Initialize
         jo.RunMethod(
    "setDataSource", _
          
    Array As Object(File.DirRootExternal, mFileName, _
          m))
         
    Log(jo.RunMethod("extractMetadata"Array As Object(9))) 'duration constant
    mFileName is the name given to the audio file recorded that is: 1.wav
    What am I doing wrong?
    Thanks for any help
    Massimiliano
     
    Last edited: Jun 2, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.
    Try:
    Code:
    jo.RunMethod("setDataSource"Array (File.Combine(File.DirRootExternal, mFileName)))
     
  3. Massy

    Massy Member Licensed User

    Hey! Thanks Erel, with your code I don't get error and I get a result... but for a file that is 5 seconds long I get 3942 value... how should I read it?
    Nevermind... I got it... they are millisec...
    Thanks for your help Erel you're great!
     
  4. DonManfred

    DonManfred Expert Licensed User

    are you sure it is really 5 seconds? I would expect it to be 3,942 seconds.
     
Loading...