Page 1 of 1

MCI correct track length

Posted: Sat Sep 07, 2024 1:45 pm
by l1marik
I am looking for function how to get correct MP3 length via MCI, using "Status length" does not return correct value. Can somebody help me?

THX

Re: MCI correct track length

Posted: Sun Sep 08, 2024 4:56 pm
by Paul

Code: Select all

Procedure.l Mci(command.s)
  Shared buffer.s
  buffer=Space(256) 
  ProcedureReturn mciSendString_(command,@buffer,256,0)
EndProcedure


file.s="C:\Users\Paul\Desktop\taxman.mp3"

If OpenWindow(0,0,0,400,80,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  ProgressBarGadget(1,10,20,380,40,0,100,#PB_ProgressBar_Smooth)
  If Mci("open "+Chr(34)+file+Chr(34)+" type MpegVideo alias mp3")=0
    Mci("set mp3 time format milliseconds")    
    Mci("status mp3 length wait")
    totallength=Val(buffer)
    SetWindowTitle(0,"Total Length: "+totallength+" ms")
    
    Mci("play mp3 from 1")
    Repeat
      Event=WaitWindowEvent(1)
      Mci("status mp3 position")
      timeleft=Val(buffer)
      
      played.f=(timeleft/totallength)*100
      SetGadgetState(1,played)
    Until Event = #PB_Event_CloseWindow
    
    Else
    Debug "Failed to open MP3"
  EndIf
EndIf

Re: MCI correct track length

Posted: Mon Sep 09, 2024 3:45 pm
by l1marik
Hi Paul, unfortunately no :-( Try it with this file: https://www.ctvrtky.info/wp-content/upl ... ffects.mp3

Lukas

Re: MCI correct track length

Posted: Mon Sep 09, 2024 3:52 pm
by Paul
l1marik wrote: Mon Sep 09, 2024 3:45 pm Hi Paul, unfortunately no :-( Try it with this file: https://www.ctvrtky.info/wp-content/upl ... ffects.mp3

Lukas
Works fine here, reports 32343 ms in length.

Tested on fresh install of Windows 8, 10 & 11 with no special CODEC pack installed.

Re: MCI correct track length

Posted: Mon Sep 09, 2024 5:03 pm
by l1marik
Hi Paul,
a, yes it shows cca 32 seconds
b, reality is cca 16 seconds :-(

Lukas

Re: MCI correct track length

Posted: Mon Sep 09, 2024 5:38 pm
by Paul
I think there is something wrong/odd with that MP3 file.

If I load it that MP3 into VLC, it briefly displays 32 seconds before changing to 16 seconds.
If I resave the file using VLC, the new file displays 16 seconds in VLC and using the MCI commands it now shows 16040ms in length.