public class MediaActionSound extends Object
A class for producing sounds that match those produced by various actions taken by the media and camera APIs.
Use this class to play an appropriate camera operation sound when
implementing a custom still or video recording mechanism (through the Camera
preview callbacks with Camera.setPreviewCallback
, or through GPU processing with Camera.setPreviewTexture
, for
example), or when implementing some other camera-like function in your
application.
There is no need to play sounds when using
Camera.takePicture
or
MediaRecorder
for still images or video, respectively,
as the Android framework will play the appropriate sounds when needed for
these calls.
Modifier and Type | Field and Description |
---|---|
static int |
FOCUS_COMPLETE
A sound to indicate that focusing has completed.
|
static int |
SHUTTER_CLICK
The sound used by
Camera.takePicture to
indicate still image capture. |
static int |
START_VIDEO_RECORDING
The sound used by
MediaRecorder.start() to
indicate the start of video recording. |
static int |
STOP_VIDEO_RECORDING
The sound used by
MediaRecorder.stop() to
indicate the end of video recording. |
Constructor and Description |
---|
MediaActionSound()
Construct a new MediaActionSound instance.
|
Modifier and Type | Method and Description |
---|---|
void |
load(int soundName)
Preload a predefined platform sound to minimize latency when the sound is
played later by
play(int) . |
void |
play(int soundName)
Play one of the predefined platform sounds for media actions.
|
void |
release()
Free up all audio resources used by this MediaActionSound instance.
|
public static final int SHUTTER_CLICK
Camera.takePicture
to
indicate still image capture.play(int)
,
Constant Field Valuespublic static final int FOCUS_COMPLETE
play(int)
,
Constant Field Valuespublic static final int START_VIDEO_RECORDING
MediaRecorder.start()
to
indicate the start of video recording.play(int)
,
Constant Field Valuespublic static final int STOP_VIDEO_RECORDING
MediaRecorder.stop()
to
indicate the end of video recording.play(int)
,
Constant Field Valuespublic MediaActionSound()
public void load(int soundName)
play(int)
.soundName
- The type of sound to preload, selected from
SHUTTER_CLICK, FOCUS_COMPLETE, START_VIDEO_RECORDING, or
STOP_VIDEO_RECORDING.play(int)
,
SHUTTER_CLICK
,
FOCUS_COMPLETE
,
START_VIDEO_RECORDING
,
STOP_VIDEO_RECORDING
public void play(int soundName)
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
Camera.takePicture
,
MediaRecorder.start
, and
MediaRecorder.stop
.
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 load(int)
before calling play,
play will load the sound at the cost of some additional latency before
sound playback begins.
soundName
- The type of sound to play, selected from
SHUTTER_CLICK, FOCUS_COMPLETE, START_VIDEO_RECORDING, or
STOP_VIDEO_RECORDING.Camera.takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback)
,
MediaRecorder
,
SHUTTER_CLICK
,
FOCUS_COMPLETE
,
START_VIDEO_RECORDING
,
STOP_VIDEO_RECORDING
public void release()