Page 2 of 2

Re: Recover duration mp3 file

Posted: Thu Mar 09, 2023 5:23 pm
by jak64
Hello Marc56us

I am using a code I found on the forum.
It's fast (0.7 seconds for over 5000 mp3s) but I don't know how to calculate the duration from what I retrieve.

Here is the code

Code: Select all

  Fichier$ = OpenFileRequester("Sélectionner un fichier","","Musique (.mp3)",0)
  If Fichier$
    If ReadFile(0, Fichier$) 
      length = Lof(0)                       ; Lit la taille en octets du fichier
      FileSeek(0, 1)                                 ;
      ;Debug "Position: " + Str(Loc(0))      ; Affiche la position du pointeur
      *MemoryID = AllocateMemory(30)        ; alloue un bloc mémoire pour 10 octets
      If *MemoryID
        bytes = ReadData(0, *MemoryID, 30)  ; Lit les 30 premiers caractères du fichier
        Debug PeekS(*MemoryID)
      EndIf
      CloseFile(0)
    EndIf
  EndIf 

Re: Recover duration mp3 file

Posted: Thu Mar 09, 2023 6:11 pm
by Bisonte
Unfortunately, determining the duration of an MP3 file requires a bit more than just
reading a value and converting it into seconds / minutes.

Framesize, framecount, bitrate, sample rate and so on are also needed to calculate the time....
there are various formulas how it has to look like. and it will take longer than 0.7 seconds ;)

Your 0.7 seconds when reading the directory with 5000 files is probably due to the fact that you
have already scanned the directory several times... something like this is buffered by Windows
and is always faster from the 2nd run onwards....

If I found my old source I will take it to the tips&tricks section....

Edit:
I found and post it.... : viewtopic.php?t=81046

Re: Recover duration mp3 file

Posted: Thu Mar 09, 2023 6:16 pm
by NicTheQuick
RASHAD wrote: Thu Mar 09, 2023 3:45 pm Professor NicTheQuick
How about remove the post and wait for your correct answer for jack64 ,If you can :wink:
What do you mean? What correct answer from jak64? There is no reason to delete any of my comments.

Re: Recover duration mp3 file

Posted: Thu Mar 09, 2023 7:06 pm
by RASHAD
@NicTheQuick
I removed my post not yours

@jack64
There is a good solution using VBS
Maybe some other fellow can do it
Or wait for me [After taking a nap] :D

Re: Recover duration mp3 file

Posted: Fri Mar 10, 2023 12:54 am
by RASHAD