Recover duration mp3 file

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 619
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: Recover duration mp3 file

Post 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 
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: Recover duration mp3 file

Post 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
Last edited by Bisonte on Thu Mar 09, 2023 6:33 pm, edited 1 time in total.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Recover duration mp3 file

Post 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.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Recover duration mp3 file

Post 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
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Recover duration mp3 file

Post by RASHAD »

Egypt my love
Post Reply