Post by Sver on Jun 6, 2019 12:06:54 GMT -5
'Bare bones MP3 player.
'This demo allows pause/resume, and
'closes MP3 for exit.
nomainwin
WindowWidth=190:WindowHeight=130
button #1.b, "Open File",[open],UL,10,10,80,26
button #1.stop, "Stop",[closeSong],UL,100,10,80,26
button #1.pause, "Pause",[pause],UL,10,40,80,26
button #1.resume, "Resume",[resume],UL,100,40,80,26
button #1.exit, "Exit",[quit],UL,100,70,80,26
open "MP3 Player" for window_nf as #1
print #1, "trapclose [quit]"
[loop]
wait
[open]
if musicOpen=1 then r$=mciSendString$("close music")
filedialog "select MP3","*.mp3",m$
if m$="" then [loop]
m$=GetShortPathName$(m$)
r$=mciSendString$("open "+m$+" type MpegVideo alias music")
musicOpen=1
r$=mciSendString$("play music")
goto [loop]
[closeSong]
r$=mciSendString$("close music")
musicOpen=0
goto [loop]
[quit]
if musicOpen=1 then r$=mciSendString$("close music")
close #1:end
[pause]
r$=mciSendString$("pause music")
goto [loop]
[resume]
r$=mciSendString$("resume music")
goto [loop]
Function mciSendString$(s$)
'Buffer will contain a return string from
'the function, if there is one.
buffer$=space$(1024)+chr$(0)
calldll #winmm,"mciSendStringA",s$ as ptr,buffer$ as ptr,_
1028 as long, 0 as long, r as long
'truncate returned string at null character
buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
if r>0 then
mciSendString$="error"
else
mciSendString$=buffer$
end if
End Function
Function GetShortPathName$(lPath$)
lPath$=lPath$+chr$(0)
sPath$=space$(256)
lenPath=len(sPath$)
calldll #kernel32, "GetShortPathNameA",lPath$ as ptr,_
sPath$ as ptr,lenPath as long,r as long
GetShortPathName$=left$(sPath$,r)
end function
Nice, but why doesn't it play a file with space WHEN the files are on a USB-stick. (example E:)
Example: 2 Unlimited.mp3 doesn't play
Example: 2Unlimited.mp3 play
When they files are on C: it works !