Playing MP3's
BlitzMax Forums/BlitzMax Beginners Area/Playing MP3's
| ||
Hi guys, I'm a former Blitz2d programmer (yeah, that far back) that's taken the plunge last night and purchased BlitzMax and MaxGUI so I can get back into programming again. Now I've kind of grown up with Blitz from the Amiga version so I've got a rough idea of what I'm doing but what I appear to be missing is a method for playing MP3's. I'm working through Assari's exellent tutorials to get used to MaxGUI so I thought i'd make myself a simple little MP3 player which can do things like save playlists and upload mp3's to my memory card for me with a nice gui front end. Of course if I can't actually play MP3's with this version of Blitz then I'm kind of at a dead end from the start as all my music is in that format and I dont want to convert it all into Ogg or (heaven forbid) Wavs. Many thanks if anyone can help me out. |
| ||
This is due to license reasons. As long as you do not own a license, you should not use MP3 in your software (5000 downloads and you need one, no mather if freeware or commercial). Thus OGG is the standard format in BM. |
| ||
this might help get you started, [EDIT] modified to use an alias name to resolve big path names ' mci based windows media controller ' derived from http://www.gamedev.net/reference/articles/article2053.asp Extern "win32" Function mciSendStringA(cmd$z,resultbuffer:Byte Ptr=Null,buffersize=0,hwndcallback=0) End Extern Local file$ Local cmd$ Local result file="E:\music\Bloc Party\Silent Alarm\01 Like Eating Glass.mp3" cmd="open ~q"+file+"~q alias mysound" result=mciSendStringA(cmd) Print "result="+result cmd="play mysound from 0" result=mciSendStringA(cmd) Print "result="+result Input "hit enter to end" End |
| ||
Thats nice Simon. Tried it with a *.wmv and it works nicely. |
| ||
This brings up an interesting point -- if your application itself does not play the MP3, but essentially uses the windows API to hand it over to the operating system to have it played instead, does your application still need a license for the MP3 functionality, or would it be covered by Microsoft's own license? |
| ||
This brings up an interesting point -- if your application itself does not play the MP3, but essentially uses the windows API to hand it over to the operating system to have it played instead, does your application still need a license for the MP3 functionality, Yes. or would it be covered by Microsoft's own license? Microsofts license only covers Microsoft.http://www.mp3licensing.com/ |
| ||
Too bad. Thanks for clearing that up, though. |
| ||
That's spot-on, skidracer. Thanks a lot for that. Being new to BlitzMax I wont even try to kid myself I understand what's going on there but I can read enough to modify it for my own use. Not that i'll go and write my own MP3 player now. If it's illegal then I can't do that even if it is just for my own use. |
| ||
For your own usage you can, but only for your own usage ... |
| ||
I would guess that only applies to software that dictates the playback of mp3 files, if it requires user selection I can't help thinking you'd be off the hook with the mp3 license. In any case, using such a method you will need to include mediaplayer7 or above in your specification / system requirements so you may as well use the superior WMA format for any tracks that the software itself is dependent on for it's function. |
| ||
I'm sure theres an open source way to convert mp3 to ogg... |
| ||
Audacity http://audacity.sourceforge.net/ |
| ||
Sorry to revisit old threads but I've got mp3 playback running ok now in my program but the slight flaw is I have no idea how to actually get the mediaplayer to stop playing the file when it's playing. I can restart it with the same function call but that's my lot. Anyone got a suggestion? |
| ||
Nobody abe to help me out here? I have no idea how to send media player an external command or even what commands it would accept but surely someone does? |
| ||
See MSDN or VB documentation on that. Both cover MP COM handling quite good. |
| ||
heres a quick classExtern "win32" Function mciSendStringA(cmd$z,resultbuffer:Byte Ptr=Null,buffersize:Int=0,hwndcallback:Int=0) End Extern Type TMusic Global musicnumber:Int=0 Field number:Int,paused:Int Field playing:Int Function Open:TMusic(sfile:String) Local music:TMusic=New TMusic music.number=TMusic.musicnumber TMusic.musicnumber:+1 music.Load(sfile) Return music End Function Method Load(sfile:String) mciSendStringA("open ~q"+sfile+"~q alias "+Name()) End Method Method Play(from:Int=0) If Not paused mciSendStringA("play "+Name()+" from "+from*1000) playing=1 Else mciSendStringA("resume "+Name()) playing=True paused=False EndIf End Method Method Pause() If paused Return mciSendStringA("pause "+Name()) paused=True playing=False End Method Method Stop() mciSendStringA("stop "+Name()) playing=False paused=False End Method Method Name:String() Return ("TMusic"+String(number)) End Method End Type |
| ||
....and an exampleLocal basketcase:TMusic=TMusic.Open("C:\Documents and Settings\All Users\Documents\My Music\Green Day\Dookie\Green Day - Basket Case.mp3") basketcase.Play() WaitKey You can specify an amount of time in seconds to start at. |
| ||
(Coming in in the middle of the discussion, so sorry 'bout that.) Skid's code works great for me, though I use Ogg for my game stuff, due to MP3 license evilness. |
| ||
khomy prime: Thanks a lot for those examples. I'll give them a test run now. WendellM: Agreed about mp3 license but it's only something I'm writing for myself so it shouldn't be an issue. I've already put in ogg support for playback but I'm a bit dissapointed about the memory hogging and slow speed in playback to consider it viable having a program play lots of ogg files in a row. Simons code was spot on for playing back an MP3 but I needed a bit more control than just playing one track hence my question. While I'm on the subject of Ogg files though is there any way of accessing the track information within blitzMax or am I looking at an external routine for that too? |
| ||
Does someone know how to get the lenght of an mp3 and the current playing positions for the example above? |
| ||
Take a look at my MP3 playing library for Blitz3D (link in signature) - it uses MCI also, so it's just a matter of adapting the strings sent to the code posted above... |
| ||
Does someone know how to get the lenght of an mp3 and the current playing positions for the example above? Various BlitzMax modules support cross-platform playback of mp3s, and allow you to see the current position as well as lots of other information. |
| ||
@brucey: could you name one please, I'm looking but can not find. @slotman: where can I find it? I'm having trouble understanding some english, not native speaking. Thanks a lot! |
| ||
Brucey is always shy about naming his own modules. Look at the links in his signature, I am sure you will find what you are looking for. |
| ||
Thanks people, I got it working (BASS)! |