Play one of the predefined platform sounds for media actions.
Use this method to play a platform-specific sound for various media
actions. The sound playback is done asynchronously, with the same
behavior and content as the sounds played by
{@link android.hardware.Camera#takePicture Camera.takePicture},
{@link android.media.MediaRecorder#start MediaRecorder.start}, and
{@link android.media.MediaRecorder#stop MediaRecorder.stop}.
With the {@link android.hardware.camera2 camera2} API, this method can be used to play
standard camera operation sounds with the appropriate system behavior for such sounds.
With the older {@link android.hardware.Camera} API, using this method makes it easy to
match the default device sounds when recording or capturing data through the preview
callbacks, or when implementing custom camera-like features in your application.
If the sound has not been loaded by {@link #load} before calling play,
play will load the sound at the cost of some additional latency before
sound playback begins.
if (soundName < 0 || soundName >= SOUND_FILES.length) {
throw new RuntimeException("Unknown sound requested: " + soundName);
}
if (mSoundIds[soundName] == SOUND_NOT_LOADED) {
mSoundIdToPlay =
mSoundPool.load(SOUND_FILES[soundName], 1);
mSoundIds[soundName] = mSoundIdToPlay;
} else {
mSoundPool.play(mSoundIds[soundName], 1.0f, 1.0f, 0, 0, 1.0f);
}