MCI correct track length

Just starting out? Need help? Post your questions and find answers here.
l1marik
User
User
Posts: 52
Joined: Tue Jun 30, 2020 6:22 am

MCI correct track length

Post 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
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: MCI correct track length

Post 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
Image Image
l1marik
User
User
Posts: 52
Joined: Tue Jun 30, 2020 6:22 am

Re: MCI correct track length

Post by l1marik »

Hi Paul, unfortunately no :-( Try it with this file: https://www.ctvrtky.info/wp-content/upl ... ffects.mp3

Lukas
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: MCI correct track length

Post 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.
Image Image
l1marik
User
User
Posts: 52
Joined: Tue Jun 30, 2020 6:22 am

Re: MCI correct track length

Post by l1marik »

Hi Paul,
a, yes it shows cca 32 seconds
b, reality is cca 16 seconds :-(

Lukas
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: MCI correct track length

Post 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.
Image Image
Post Reply