Page 1 of 1
MCI Replacement? How to play mp3?
Posted: Wed Jun 22, 2016 8:31 pm
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)
Re: MCI Replacement? How to play mp3?
Posted: Wed Jun 22, 2016 10:48 pm
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
Re: MCI Replacement? How to play mp3?
Posted: Thu Jun 23, 2016 4:02 am
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

Re: MCI Replacement? How to play mp3?
Posted: Thu Jun 23, 2016 7:02 am
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
Re: MCI Replacement? How to play mp3?
Posted: Thu Jun 23, 2016 10:52 am
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
Re: MCI Replacement? How to play mp3?
Posted: Thu Jun 23, 2016 1:34 pm
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...
Re: MCI Replacement? How to play mp3?
Posted: Thu Jun 23, 2016 4:28 pm
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
Re: MCI Replacement? How to play mp3?
Posted: Fri Jun 24, 2016 12:58 pm
by dige
Wow, thats strange.

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?

Re: MCI Replacement? How to play mp3?
Posted: Sat Jun 25, 2016 5:38 pm
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