Audio¶
Audio files¶
Any audio file that is supported by Android can be used.
Initialization¶
The engine provides a service to easily play sounds or implement a new
audio service by implementing the interface AudioService.
The following example shows how to use the audio service locator to provide an audio service throughout your app, decoupling graphics and sound.
For the initialization:
1 2 | AudioService audioService = new SoundWorkerImpl(getApplicationContext(), 5); AudioServiceLocator.provideService(audioService); |
The default implementation SoundWorkerImpl of the engine is used here,
which lets us specify the maximum number of sounds that can be played
simultaneously (it's set to 5 here).
After that, we use the AudioServiceLocator class to provide this
newly created service.
To use this service in any part of your app you simply call:
1 | AudioService audioService = AudioServiceLocator.getAudioService(); |
Now you can use audioService to access the features provided by this
interface.