Re:music

BlitzMax Forums/BlitzMax Beginners Area/Re:music

Joe90(Posted 2011) [#1]
In my program I have several music tracks so when you press a key it advances the track number and plays a different track.
What I want to know is this.
I want the track playing when it finishes it goes onto the next track.
How can i code it so that when it reaches the end of a track to go onto the next track.
Ive got a variable MusicTrack_Number and when i press a key i increase it by 1 and then i have case statements to change the track depending on MusicTrack_Number.
I just wondered if theres any code i can use so that when the current track is playing and then ends to advance onto the next track in the list.
Thanks guys
Cheers
Kind Regards
Joe


shinkiro1(Posted 2011) [#2]
Maybe use an array instead of a list, because there you have an index and can just use your MusicTrack_Number for that.

If you want to know when the track ends, you will have to use a third party module, bmax audio module is not capaple of this.
Search for maxmod2.


GfK(Posted 2011) [#3]
bmax audio module is not capaple of this.
That's not entirely true. You can use ChannelPlaying() to see if a channel has stopped - thought it also returns True even if the channel has been manually paused.

But yeah, MaxMod2 should do the job nicely.


Kryzon(Posted 2011) [#4]
I was hoping a callback could be elegantly used for this, but apparently not. You really have to poll (i.e: check every cycle the state of the channel).


Joe90(Posted 2011) [#5]
Ok thanks guys.
yeah you cant really use channelplaying () as it always returns true.
If i use if channelplaying (channel) = false it never works.
Yeah how do you check every cycle the state of the channel so i can use channelplaying()


Kryzon(Posted 2011) [#6]
[...] though it also returns True even if the channel has been manually paused.

[...]
yeah you cant really use channelplaying () as it always returns true.
If i use if channelplaying (channel) = false it never works.
[...]

This doesn't make sense. The BMax audio code is flawless in this respect:
Method Playing()
	Local st
	alGetSourcei _id,AL_SOURCE_STATE,Varptr st
	Return st=AL_PLAYING 
End Method
There's the AL_PLAYING, AL_PAUSED and AL_STOPPED states declared; it must return 'False' when paused and stopped or else the BRL code above is wrong.

Last edited 2011


GfK(Posted 2011) [#7]
I meant to say it returns false if a channel has been manually paused. my bad.


Joe90(Posted 2011) [#8]
ok so ive got several tracks in my code.
When the game starts it plays a random track.
How can i check that when the track is finished i can play another random track.
I dont wanna use maxmod2. I just wanna use blitz max.
The above code doesnt make any sense to me whatsoever.
Cant i use channelplaying to check the state of the channel.
Whats that all about alGetsource _id. It does nothing. It doesnt return the state of a channel?????????
Im confused by the above code.
I dont get it!!!!!


Kryzon(Posted 2011) [#9]
You can use ChannelPlaying to check if the sound is still playing.
Use it like this:
If Not ChannelPlaying( CurrentChannel ) Then
	MusicID :+ 1	'Shorter way to say MusicID = MusicID + 1
	
	If MusicID < NumberOfMusics Then
		CurrentChannel = PlaySound( Musics[MusicID] )
	Else
		MusicID = 0	'Loop through all musics again.
	EndIf
EndIf



Joe90(Posted 2011) [#10]
ahhh cool nice one Kryzon. That looks like just what i need.
Thanks very much!!!