Page 1 of 1

Playing MP3 music files

Posted: Fri May 19, 2006 7:14 pm
by MikeB
I sometimes want to play a music file (often speech) while a program is running. I have usually used .wav files which is simple enough using a thread or to play once, using a separate program started with run program. However to cut down on file size and speed the loading I would like to use MP3 files as I already have them. The question is can PB play these without using the Mci() command to pass strings, this works but I don't like doing it this way. I can use Ogg Varbis, which is as easy as .wav (using UseOGGSoundDecoder()) but this means making another file just for this as I don't think I have anything else that can play .Ogg files.

Posted: Fri May 19, 2006 8:28 pm
by dioxin
Mike,
<< this works but I don't like doing it this way>>

Why not? It's simple and it works, what more could you want?

Paul.

Posted: Fri May 19, 2006 8:51 pm
by Trond
It's not cross-platform.

Posted: Fri May 19, 2006 9:03 pm
by MikeB
There is a good reason why I don't like doing it using Mci(), I have copied the relevant bits from a player by Dominique Bodin and it works, but I don't have a clue as to what is happening and can't find any reference to it anywhere else. :?

On the other hand quite a lot of my programs have bits that work without my knowing how! :lol:

Posted: Fri May 19, 2006 9:09 pm
by utopiomania
Use the built in Movie library, playMovie().., or a webgadget if you can live with loop, or << >>. ? :)

Posted: Fri May 19, 2006 9:13 pm
by josku_x
yeah, a good idea is to use the movie library, because it supports MPEG videos, and MP3 is just a variation of MPEG. So it should work, shouldn't it?

Posted: Fri May 19, 2006 9:18 pm
by Joakim Christiansen
http://msdn.microsoft.com/library/defau ... 2_open.asp
Look here for all the information you'll need on MCI strings!

And this page is also very good:
http://www.geocities.com/smigman.geo/mci/mci.html

Code: Select all

If mciSendString_("OPEN "+#DQUOTE$+File+#DQUOTE$+" ALIAS Media",0,0,0)=0
  mciSendString_("PLAY Media",0,0,0)
  Delay(5000)
  mciSendString_("STOP Media",0,0,0)
  mciSendString_("CLOSE Media",0,0,0)
Else
  ;error
EndIf
I'm making a MCI media player, it's fun!

Posted: Fri May 19, 2006 9:20 pm
by josku_x
I have done one 2 years ago, it's really simple, but sometimes just not so fleixble and efficient. I ended up using FMOD and a simple wrapper I made myself.

Posted: Fri May 19, 2006 9:30 pm
by MikeB
Thanks utopiomania,
Have just tried using the movie commands and it works a treat, also alleviates the need to use a thread to run asynchronously. :D

Posted: Sat May 20, 2006 6:44 am
by Baldrick
MikeB,
Don't know if this may be of any use for you, but I made a little Mp3 lib up a while ago based around simple use of Mcistrings. I havent looked at updating it for V4 yet though.
If you don't want to use it as a user lib with PB, I have included the source in the download which you may find usefull to help teach yourself how Mci works.
Lib, helpfile and source can be downloaded from here for PB 3.94 - http://www.purearea.net/pb/download/userlibs/DeMp3.zip

Posted: Sat May 20, 2006 10:59 am
by MikeB
Thanks Baldrick, actually your userlib is one of the things I had downloaded in my initial search for a method of playing MP3s. I tried it (using PB V4) and got a string of linker errors. I saw that it was for PB 3.94 and assumed that was the reason and went on to try alternative methods. To convert for V4 seems to me to be just a matter of changing the variables to pointers for the PeekS() commands but I have never tried making a library so apart from not knowing how to do it, I might well be talking piffle. I must have a look at how to make a library when I have time, so far I have seen in the PB help file about making .dll files, but that is not the same and as far as I can see makes the calls more complicated instead of easier. :?

Posted: Sat May 20, 2006 11:43 am
by Baldrick
Yes,
The pointers are pretty much all there is, I have not bothered at this stage as I decided better to wait until V4 is stable before I put Tailbite back in, etc.
All I need is a little motivation & I will probably update it soon.
Meanwhile, the source with the lib might be helpfull to you as copy , paste & modify directly into your code.

Hi MikeB

Posted: Sat May 20, 2006 4:50 pm
by DominiqueB
I've read your post.
Do you mean you don't have the code for my player ?
If anyone needs it i can send it for free . . .

Just ask with your e-mail adress cause i've no way to post it anywhere else.

Dominique

Posted: Sat May 20, 2006 8:20 pm
by MikeB
DominiqueB, I downloaded your player and it works fine as a player, but what I have done as well as keeping it in the original form as a player, is to take just the bits I needed to play one particular MP3 file in the background of another program. For the purpose I only need to load the file, play it and detect when it is finished so I didn't need the whole thing.
:D