Quick and easy mp3 playing

General FreeBASIC programming questions.
badmrbox
Posts: 664
Joined: Oct 27, 2005 14:40
Location: Sweden
Contact:

Post by badmrbox »

Couldn't sleep just yet so I tried it with fbc0.17. Same problems as with fbc0.16 but maybe that's not so strange. When I tried to run one of the test's from fb I got this error 'cannot find -lfbsoundwin'. What is that and why don't I have it?
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Post by KristopherWindsor »

To answer the original question, the easiest way to play sound is through this .BI file that contains code modified from someone's FB MP3 player. The test program works if you have the called files. You can also pass URLs instead of file names. :-)

Imci.bi:

Code: Select all

' (C) 2007 i-TECH and Kristopher Windsor

#include once "windows.bi"
#include once "win/mmsystem.bi"

Const imci_standby = 0, imci_playing = 1

Dim Shared As Integer imci_mode
Dim Shared As Double imci_timer
Dim Shared As String imci_file

Declare Sub imci_stop

Sub imci_play (filename As String)
  imci_stop 'stops current audio
  If imci_mode = imci_standby Then
    'open audio file
    mciSendString("open """ + filename + """ type mpegvideo alias " + filename, NULL, 0, 0)
    'start playing
    mciSendString("play """ + filename + """ from 0", NULL, 0, 0)
    'set timer when audio starts
    imci_timer = Timer
    'set mode
    imci_file = filename
    imci_mode = imci_playing
  End If
End Sub

Sub imci_stop
  If imci_mode = imci_playing Then
    'close audio file
    mciSendString("close """ + imci_file + """", NULL, 0, 0)
    'set timer when audio stops
    imci_timer = Timer
    'set mode
    imci_mode = imci_standby
  End If
End Sub

Function imci_playtime as double
  Return Timer - imci_timer
End Function
IMCITest.bas:

Code: Select all

#include "imci.bi"

imci_play "C:\music.mp3"
Sleep
imci_play "C:\music2.mp3" 'calls imci_stop to close previous audio file
Sleep
imci_stop 'must be called at the end of the program
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

KristopherWindsor wrote:To answer the original question, the easiest way to play sound is through this .BI file that contains code modified from someone's FB MP3 player.
Assuming of course you have windows. :)
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

maddogg6 wrote:I presume you mean - in addition to what I posted before that I needed to comment out..

Code: Select all

'#define WAVE_FORMAT_1M08 &h00000001
'#define WAVE_FORMAT_1S08 &h00000002
'#define WAVE_FORMAT_1M16 &h00000004
'#define WAVE_FORMAT_1S16 &h00000008
'#define WAVE_FORMAT_2M08 &h00000010
'#define WAVE_FORMAT_2S08 &h00000020
'#define WAVE_FORMAT_2M16 &h00000040
'#define WAVE_FORMAT_2S16 &h00000080
'#define WAVE_FORMAT_4M08 &h00000100
'#define WAVE_FORMAT_4S08 &h00000200
'#define WAVE_FORMAT_4M16 &h00000400
'#define WAVE_FORMAT_4S16 &h00000800
Since I don't do win programming in FB (I use Delphi for that :)), it hasn't been a problem for me. However, a better solution is to wrap the defines in an #ifndef:

Code: Select all

#ifndef __win_mmsystem_bi__
#define WAVE_FORMAT_1M08 &h00000001
#define WAVE_FORMAT_1S08 &h00000002
#define WAVE_FORMAT_1M16 &h00000004
#define WAVE_FORMAT_1S16 &h00000008
#define WAVE_FORMAT_2M08 &h00000010
#define WAVE_FORMAT_2S08 &h00000020
#define WAVE_FORMAT_2M16 &h00000040
#define WAVE_FORMAT_2S16 &h00000080
#define WAVE_FORMAT_4M08 &h00000100
#define WAVE_FORMAT_4S08 &h00000200
#define WAVE_FORMAT_4M16 &h00000400
#define WAVE_FORMAT_4S16 &h00000800
#endif
I updated my bass.bi file with the above code and compiled your example and my example and everything worked fine. This will give you a bit more flexibility and will work if you are using win or not.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

badmrbox wrote:Couldn't sleep just yet so I tried it with fbc0.17. Same problems as with fbc0.16 but maybe that's not so strange. When I tried to run one of the test's from fb I got this error 'cannot find -lfbsoundwin'. What is that and why don't I have it?
1) get fbsound 0.03
http://alice-dsl.net/d.j.peters/fbsound/fbsound0.03.zip
2) extraxt it
for example to c:
3) open a console
c:
cd \fbsound0.03
makeall.bat

4) please report any error/warning message if any

5) cd tests

6) dir *.exe
it should be over 20 in the folder

Joshy
dani.user
Posts: 284
Joined: Sep 30, 2006 10:41

Post by dani.user »

Fbsound is very nice. Thank you for creating it
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

dani.user wrote:Fbsound is very nice. Thank you for creating it
thanx i like it too :-)
dani.user
Posts: 284
Joined: Sep 30, 2006 10:41

Post by dani.user »

Is any license required for playing mp3 files?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

dani.user wrote:Is any license required for playing mp3 files?
simple NO and the sound lib is for commercial apps free too.
Post Reply