Playing MP3's

BlitzMax Forums/BlitzMax Beginners Area/Playing MP3's

Xerra(Posted 2006) [#1]
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.


Dreamora(Posted 2006) [#2]
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.


skidracer(Posted 2006) [#3]
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



EOF(Posted 2006) [#4]
Thats nice Simon. Tried it with a *.wmv and it works nicely.


xlsior(Posted 2006) [#5]
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?


FlameDuck(Posted 2006) [#6]
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/


xlsior(Posted 2006) [#7]
Too bad. Thanks for clearing that up, though.


Xerra(Posted 2006) [#8]
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.


Dreamora(Posted 2006) [#9]
For your own usage you can, but only for your own usage ...


skidracer(Posted 2006) [#10]
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.


Chris C(Posted 2006) [#11]
I'm sure theres an open source way to convert mp3 to ogg...


bradford6(Posted 2006) [#12]
Audacity

http://audacity.sourceforge.net/


Xerra(Posted 2006) [#13]
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?


Xerra(Posted 2006) [#14]
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?


Dreamora(Posted 2006) [#15]
See MSDN or VB documentation on that. Both cover MP COM handling quite good.


kfprimm(Posted 2006) [#16]
heres a quick class

Extern "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



kfprimm(Posted 2006) [#17]
....and an example

Local 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.


WendellM(Posted 2006) [#18]
(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.


Xerra(Posted 2006) [#19]
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?


asoed(Posted 2009) [#20]
Does someone know how to get the lenght of an mp3 and the current playing positions for the example above?


SLotman(Posted 2009) [#21]
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...


Brucey(Posted 2009) [#22]
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.


asoed(Posted 2009) [#23]
@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!


TaskMaster(Posted 2009) [#24]
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.


asoed(Posted 2009) [#25]
Thanks people, I got it working (BASS)!