MCI Replacement? How to play mp3?

Windows specific forum
dige
Addict
Addict
Posts: 1406
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

MCI Replacement? How to play mp3?

Post by dige »

Hi folks, I still use mci and I like it. Its easy and works.

But now I've found out, that mci cannot read some mp3 files properly.
mciSendString_("status alias length",..) returns a wrong duration.

Ok, I know, mci is obsolete .. and the day must be come that this happens..
But what else?

I've tried LoadMovie -> MovieLength = 0
I've tried LoadSound -> failed

What is the best way mp3s play?

Code: Select all

name.s = "c:\temp\test.mp3" 

Debug mciSendString_("open " + Chr(34) + name + Chr(34) + " type mpegvideo alias song", 0, 0, 0)
Debug mciSendString_("set song time format ms", 0, 0, 0)

*mem = AllocateMemory(16)
Debug mciSendString_("status song length", *mem, 16, 0)
len.s = PeekS(*mem)
Debug FormatDate( "%ii:%ss", Val(len)/1000) + " min:sec"

Debug InitMovie()
Debug LoadMovie(0, name)
Debug MovieLength(0)
Debug MovieInfo(0, 0)

Debug InitSound()
Debug LoadSound(0, name)
Debug SoundLength(0, #PB_Sound_Millisecond)

"Daddy, I'll run faster, then it is not so far..."
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: MCI Replacement? How to play mp3?

Post by RASHAD »

Hi dige
Install the latest K-Lite codecs
Arrow Up or Down to increase or decrease volume
Tested with Windows 10 x64 :)

Code: Select all

;0 = "cdaudio" 		     - For playing tracks on a CD.
;1 = "AVIVideo" 		   - For playing AVI And other video files. 
;2 = "sequencer"       - For playing MIDI files.
;3 = "waveaudio"		   - For playing WAV files.
;4 = "MPEGVideo"       - For Playing Video or Audio Files

;Volume from 0 To 1000
Volume = 1000
OpenWindow(0, 0, 0,300,40, "", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Filename$ = OpenFileRequester("","","ALL|*.*;*.mid|Wave|*.wav|mp3|*.mp3|OGG|*.OGG|MID|*.MID",0) 
If Filename$
      mciSendString_("OPEN "+Chr(34)+Filename$+Chr(34)+" Type MPEGVideo ALIAS "+Str(0),0,0,0) 
      Length$ = Space(#MAX_PATH) 
      Pos$ = Space(#MAX_PATH) 
      mciSendString_("Status "+Str(0)+" length",@Length$,#MAX_PATH,0)
      mciSendString_("Play "+Str(0),0,0,0)
 EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
 
    Case #WM_KEYDOWN  
      If EventwParam() = 38
        keybd_event_(#VK_VOLUME_UP,0,0,0)
        keybd_event_(#VK_VOLUME_UP,0,#KEYEVENTF_KEYUP,0)
      ElseIf EventwParam() = 40
        keybd_event_(#VK_VOLUME_DOWN,0,0,0)
        keybd_event_(#VK_VOLUME_DOWN,0,#KEYEVENTF_KEYUP,0)     
      EndIf
    mciSendString_("Status "+Str(Nb)+" position",@Pos$,#MAX_PATH,0)
  EndSelect
Until Val(Pos$) >= Val(Length$) Or Quit = 1 
Egypt my love
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: MCI Replacement? How to play mp3?

Post by Keya »

Also the LAME codec seems very popular for mp3, and my understanding with mp3 is that as long as you're only decoding and not encoding you dont have to worry about royalties to Fraunhoffer. Search: mp3 lame -keya :D
dige
Addict
Addict
Posts: 1406
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: MCI Replacement? How to play mp3?

Post by dige »

@RASHAD: could you test it please with that song:

http://s9.clip.dj/downy.php?f=3&id=XaEa ... e5640c39bf

Installed k-lite 12.1.5 Win10 x64...same wrong results
"Daddy, I'll run faster, then it is not so far..."
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: MCI Replacement? How to play mp3?

Post by RASHAD »

Hi dige
It works like a charm my friend
Use LAV decoder and play with its settings specially bitstreaming( manage both 32 & 64 versions)
It works too with Direct show but as you said MCI is fantastic and simple to use
Egypt my love
dige
Addict
Addict
Posts: 1406
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: MCI Replacement? How to play mp3?

Post by dige »

RASHAD, it works? You mean, if you load the mentioned mp3 file via mci, you'll get the right duration?
It should be 2:52min. I get 15:35min...
"Daddy, I'll run faster, then it is not so far..."
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: MCI Replacement? How to play mp3?

Post by RASHAD »

Yes I get the right duration

Code: Select all

OpenWindow(0, 0, 0,300,40, "", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Filename$ = OpenFileRequester("","","ALL|*.*;*.mid|Wave|*.wav|mp3|*.mp3|OGG|*.OGG|MID|*.MID",0)
If Filename$
      mciSendString_("OPEN "+Chr(34)+Filename$+Chr(34)+" Type MPEGVideo ALIAS "+Str(0),0,0,0)
      Length$ = Space(#MAX_PATH)
      Pos$ = Space(#MAX_PATH)
      mciSendString_("Status "+Str(0)+" length",@Length$,#MAX_PATH,0)
      Duration.f = ValF(length$)   ;in milliseconds
      Duration = Duration / 1000 /60 ;in minutes
      Debug "Min : "+ Str(Int(Duration)) + "  Sec : "+ Str((Duration - Int(Duration))*60)
      mciSendString_("Play "+Str(0),0,0,0)
 EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
 
    Case #WM_KEYDOWN 
      If EventwParam() = 38
        keybd_event_(#VK_VOLUME_UP,0,0,0)
        keybd_event_(#VK_VOLUME_UP,0,#KEYEVENTF_KEYUP,0)
      ElseIf EventwParam() = 40
        keybd_event_(#VK_VOLUME_DOWN,0,0,0)
        keybd_event_(#VK_VOLUME_DOWN,0,#KEYEVENTF_KEYUP,0)     
      EndIf
    mciSendString_("Status "+Str(Nb)+" position",@Pos$,#MAX_PATH,0)
  EndSelect
Until Val(Pos$) >= Val(Length$) Or Quit = 1 
Egypt my love
dige
Addict
Addict
Posts: 1406
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: MCI Replacement? How to play mp3?

Post by dige »

Wow, thats strange. :shock: I've the same Windows (Win 10 x64), PB 5.42 LTS and k-Lite 12.1.5 installed.

I get 15 min : 36 sec as duration for tht wikinger song.. how could that be? :?
"Daddy, I'll run faster, then it is not so far..."
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: MCI Replacement? How to play mp3?

Post by RASHAD »

Hi dige
The problem raised with Media player codec pack
Uninstalled it then installed K-Lite but that did not solve the problem
Shark007 advanced codecs v617 solved the problem
There is a newer version but it is buggy
Egypt my love
Post Reply