C4 Engine
C4 Engine API Documentation

Sound::PlaySound

Defined in:  C4Sound.h
Plays a sound.
Prototype

SoundResult PlaySound(void);

Description
Calling the PlaySound function causes the sound to begin playing immediately. If the sound is already playing, then calling PlaySound again has no effect.

If the sound is spatialized and has distance delay enabled (see Sound::SetSoundFlags), then the sound begins playing after a travel delay determined by the position of the listener. If the Doppler effect is also enabled, then the delay can be modified by the motion of both the sound and the listener so that the sound becomes audible at the correct time.

When the sound finishes playing, its completion callback function is invoked. A completion callback function can be installed by using the Completable::SetCompletionCallback function.

The PlaySound function returns one of the following sound result codes.
kSoundOkay The sound has successfully begun playing.
kSoundPlayFailed There are too many sounds playing. In this case, the sound object behaves as if it had played through and completed. The completion callback function is still invoked, and nonpersistent sounds are still destroyed.
Special Considerations
If a sound object is nonpersistent (the default for non-streamed sounds), then it should never be referenced after the PlaySound function has been called for it. Nonpersistent sound objects automatically self-destruct when they have finished playing, making any subsequent references to the object illegal.
See Also

Sound::StopSound

Sound::PauseSound