MP3 Player

In this category you can exchange your programming questions and solutions.
cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

MP3 Player

Post: # 794Post cvirus
Fri Jan 06, 2012 1:42 pm

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

MP3 Player

Post: # 795Post Marco
Fri Jan 06, 2012 9:02 pm

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

Yam
Posts: 11
Joined: Mon Apr 23, 2007 11:36 am

MP3 Player

Post: # 796Post Yam
Fri Jan 06, 2012 11:23 pm

check this:
http://www.fnxbasic.com/cgi-bin/yabb2/YaBB.pl?num=1182649593

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

MP3 Player

Post: # 797Post cvirus
Tue Jan 10, 2012 5:01 pm

Thank you for the reply, Thanks

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

MP3 Player

Post: # 798Post cvirus
Tue Jan 10, 2012 6:27 pm

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

fred
Posts: 54
Joined: Thu Apr 23, 2009 10:08 am

MP3 Player

Post: # 799Post fred
Tue Jan 10, 2012 7:02 pm

Did not try it but perhaps spaces
"Type -> " Type
"from -> " from

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

MP3 Player

Post: # 800Post cvirus
Wed Jan 11, 2012 3:25 pm

No, still wont work. Windows 7 maybe the reason is my S.O? :-[

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

MP3 Player

Post: # 801Post Marco
Wed Jan 11, 2012 8:30 pm

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

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

MP3 Player

Post: # 802Post cvirus
Wed Jan 11, 2012 8:41 pm

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?

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

MP3 Player

Post: # 803Post cvirus
Thu Jan 12, 2012 12:56 pm

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

Post Reply