MAV with ChannelPlaying

Blitz3D Forums/Blitz3D Beginners Area/MAV with ChannelPlaying

Polarix(Posted March) [#1]
I got debug mode on but it still says memory access violation. Please help me with this.



Thanks


RemiD(Posted March) [#2]
before the mainloop :
global Camera = createcamera()

global Listener = createlistener(Camera)

Global ThingMesh = CreateMesh() 

Global ThingSound = Load3DSound("sound.wav")
Global ThingChannel


during the mainloop :
;for a looped sound :
If( Not ChannelPlaying(ThingChannel) )
 ThingChannel = EmitSound(ThingSound,ThingMesh)
 ChannelVolume(ThingChannel,1.0)
EndIf

;for one time played sound :
If( Keyhit(57)=true ) ;space key
 ThingChannel = EmitSound(ThingSound,Camera)
 ChannelVolume(ThingChannel,1.0)
endif



Dan(Posted March) [#3]
here is an example that works:



From what i have discovered by trying this is:

PlaySound(sndWave) sets a channel for the loaded sample.

After PlaySound is called, ChannelPlaying can be used to Pause/Play this channel, but only if the sample has not reached the end.

After the sample has been played to the end, the PlaySound(sndWave) need to be assigned again to a channel.


Zethrax(Posted March) [#4]
After PlaySound is called, ChannelPlaying can be used to Pause/Play this channel, but only if the sample has not reached the end.
ChannelPlaying returns True (1) if the channel is still playing and False (0) if it has stopped ( http://www.blitzbasic.com/b3ddocs/command.php?name=ChannelPlaying&ref=2d_cat ). PauseChannel and ResumeChannel are used to pause and resume a channel.

When you use LoadSound to load a sound the value returned is a handle for the sound source object - not a channel object. PlaySound returns the channel handle that you would use with ChannelPlaying and other channel commands, so that may be where things are going pear shaped. The channel is basically a sound instance that references sound data from the sound source object. Also make sure that the sound data has actually been loaded. Any load command will return a zero if there was an issue loading whatever you needed to load.

Here's an example from the ChannelPlaying docs at http://www.blitzbasic.com/b3ddocs/command.php?name=ChannelPlaying&ref=2d_cat

sound = LoadSound( "<your sound here>" )
channel = PlaySound( sound )
Print "PlaySound: " + ChannelPlaying( channel )
Delay 4000
PauseChannel channel
Print "PauseChannel: " + ChannelPlaying( channel )
Delay 2000
ResumeChannel channel
Print "ResumeChannel: " + ChannelPlaying( channel )
Delay 2000
StopChannel channel
Print "StopChannel: " + ChannelPlaying( channel )
WaitKey
End