Game Development Reference
In-Depth Information
How it works…
System Sound Services is particularly used for playing audio alerts and simple game sound
effects such as click sound for moving a character in the game. Every sound that is played
using this is assigned a systemSoundID . All of the tracking is based on this ID, such as
stopping, pausing, and different actions that can be applied on an audio. All we have to do
is add this set of lines to play a sound:
NSString *samplePath = [[NSBundle mainBundle]
pathForResource:@"sample-sound" ofType:@"caf"];
NSURL *sampleURL = [NSURL fileURLWithPath:samplePath];
AudioServicesCreateSystemSoundID((__bridge
CFURLRef)sampleURL, &self.sampleSound);
AudioServicesPlaySystemSound(self.sampleSound);
The sampleSound is declared as a SystemSoundID property so that the sound can be
disposed later in the dealloc method. If the sound is disposed immediately after the Au-
dioServicesPlaySystemSound method, then the sound will never play.
There are some disadvantages of System Sound Services, such as only .caf , .aif , and
.wav audio file formats are supported, sounds cannot be more than 30 seconds, and only
one sound can be played at a time.
Search WWH ::




Custom Search