Page 1 of 2

MP3 Player

Posted: Fri Jan 06, 2012 1:42 pm
by cvirus
Hello Admin, i`m trying to code in fnx basic a simple mp3 player but i`m not sure how to, i know that i must declare this first.

[code]declare mci as "mciSendStringA" of "Winmm.dll"
  lpstrCommand As String
  lpstrReturnString As String byaddress
  uReturnLength As integer
  hwndCallback As integer
  result as integer
end declare[/code]

This is almost like the declare function of VB, but how to put this to work?

Like this?

[code]
if play button event then

mci "play mysound"
[/code] :D

MP3 Player

Posted: Fri Jan 06, 2012 9:02 pm
by Marco
Hi, you can try this:

declare mci as "mciSendStringA" of "Winmm.dll"
lpstrCommand As String
lpstrReturnString As String byaddress
uReturnLength As integer
hwndCallback As integer
result as integer
end declare

dim filename as string
filename=chr$(34)+exepath+"test.mp3"+chr$(34)

mci.lpstrcommand="Open "+filename
mci.execute

mci.lpstrcommand="Play "+filename
mci.execute
showmessage "Wait until sound has finished."

mci.lpstrcommand="Close "+filename
mci.execute

Check if the path of your mp3 file is correct, exepath is the path where your application is.
I hope this will help,best regards

MP3 Player

Posted: Fri Jan 06, 2012 11:23 pm
by Yam
check this:
http://www.fnxbasic.com/cgi-bin/yabb2/YaBB.pl?num=1182649593

MP3 Player

Posted: Tue Jan 10, 2012 5:01 pm
by cvirus
Thank you for the reply, Thanks

MP3 Player

Posted: Tue Jan 10, 2012 6:27 pm
by cvirus
Hello again, this is my code so far, some based on the yam and admin, but for some reason does`t seems to work.

declare mci as "mciSendStringA" of "Winmm.dll"
     lpstrCommand As String
     lpstrReturnString As String byaddress
     uReturnLength As integer
     hwndCallback As integer
     result as integer
end declare

Declare GetShortPathName as "GetShortPathNameA" of "kernel32"
     lpszLongPath As String
     lpszShortPath As String
     lBuffer As Single
end declare

object janela as form
? height = 100
? width? = 400
? caption = "Tiny MP3 Player V 0.1"
? AutoSize = false
? WindowState = 0      
? object btnopen as button
     left = 10
     top? = 30
     caption = "Open"
     onclick = open_file
? end object
? object btnplay as button
     left = 100
     top? = 30
     caption = "Play"
     onclick = play_file
? end object
? dim file as filedialog
end object

janela.showmodal


dim alias as string



sub open_file()
     file.caption = "Select an mp3 player"
     file.filter = "Mp3 Files(*.mp3)|*.mp3"
     file.show
     alias = part$(file.filename,"",instr(file.filename,"."))
     alias = field$(alias,".",1)
     alias = left$(alias,2)
end sub

sub play_file
? ?mci.lpstrcommand="Open "+chr$(34)+file.filename + chr$(34)+"TYPE MpegVideo ALIAS " + alias
? ?mci.execute
? ?mci.lpstrcommand="Play "+alias+"from 0"
? ?mci.execute
end sub

MP3 Player

Posted: Tue Jan 10, 2012 7:02 pm
by fred
Did not try it but perhaps spaces
"Type -> " Type
"from -> " from

MP3 Player

Posted: Wed Jan 11, 2012 3:25 pm
by cvirus
No, still wont work. Windows 7 maybe the reason is my S.O? :-[

MP3 Player

Posted: Wed Jan 11, 2012 8:30 pm
by Marco
Hi I placed a space for from and for type. Then it works on XP. I tested the execute on win7 ultimate, it works also. Is your mp3 file corrupt or wrong format? Sometimes mp3 files has that problem.
Do you have really an alias name just find out with showmessage or print.
you can also find out the result after the open function, it must be greater than 0.

best regards

MP3 Player

Posted: Wed Jan 11, 2012 8:41 pm
by cvirus
I?m sorry but i did not undestand what you suggest, i have tried several mp3 and none worked, i must get rid of that alias and get other.

i must put lbl.caption = alias to see if is working or showmessage alias?

MP3 Player

Posted: Thu Jan 12, 2012 12:56 pm
by cvirus
well i have changed a bit the code, can you guys see if this is working?

declare mci as "mciSendStringA" of "Winmm.dll"
  lpstrCommand As String
  lpstrReturnString As String byaddress
  uReturnLength As integer
  hwndCallback As integer
  result as integer
end declare

Declare GetShort as "GetShortPathNameA" of "kernel32"
  lpszLongPath As String
  lpszShortPath As String byaddress
  lBuffer As integer
end declare

object janela as form
  height = 100
  width  = 400
  caption = "Tiny MP3 Player V 0.1"
  AutoSize = false
  WindowState = 0 
  object btnopen as button
  left = 10
  top  = 30
  caption = "Open"
  onclick = open_file
  end object
  object btnplay as button
  left = 100
  top  = 30
  caption = "Play"
  onclick = play_file
  end object
  object lbl as label
  left = 10
  top  = 10
  end object
end object
janela.showmodal

dim filename as string

sub open_file()
  dim file as filedialog
  file.caption = "Select an mp3 player"
  file.buttontext="Open"
  file.initialdir=dir$("@")
  file.filter = "Mp3 Files(*.mp3)|*.mp3"
  file.show
  filename=file.filename
  lbl.caption=filename
end sub

sub play_file
   mci.lpstrcommand=""
   mci.uReturnLength=0
   mci.hwndCallback=0

   dim shortname as string
   getshort.lBuffer=255
   getshort.lpszLongPath=filename
   getshort.execute
   shortname=getshort.lpszShortPath
     
   mci.lpstrcommand="open "+shortname+" type mpegvideo alias mysound"
   mci.execute
   mci.lpstrcommand="play mysound"
   mci.execute
end sub