Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/media/MediaActionSound#constants) \| [Ctors](https://developer.android.com/reference/android/media/MediaActionSound#pubctors) \| [Methods](https://developer.android.com/reference/android/media/MediaActionSound#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaActionSound#inhmethods)

# MediaActionSound

*** ** * ** ***

` public class MediaActionSound `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaActionSound |

<br />

*** ** * ** ***

<br />

A class for producing sounds that match those produced by various actions taken by the media and camera APIs. It is recommended to call methods in this class in a background thread since it relies on binder calls.

This class is recommended for use with the `https://developer.android.com/reference/android/hardware/camera2/package-summary` API, since the camera2 API does not play any sounds on its own for any capture or video recording actions.

With the older `https://developer.android.com/reference/android/hardware/Camera` API, 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 `https://developer.android.com/reference/android/hardware/Camera#setPreviewCallback(android.hardware.Camera.PreviewCallback)`, or through GPU processing with `https://developer.android.com/reference/android/hardware/Camera#setPreviewTexture(android.graphics.SurfaceTexture)`, for example), or when implementing some other camera-like function in your application.

There is no need to play sounds when using `https://developer.android.com/reference/android/hardware/Camera#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)` or `https://developer.android.com/reference/android/media/MediaRecorder` for still images or video, respectively, as the Android framework will play the appropriate sounds when needed for these calls.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/media/MediaActionSound#FOCUS_COMPLETE` A sound to indicate that focusing has completed. |
| `int` | `https://developer.android.com/reference/android/media/MediaActionSound#SHUTTER_CLICK` The sound used by `https://developer.android.com/reference/android/hardware/Camera#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)` to indicate still image capture. |
| `int` | `https://developer.android.com/reference/android/media/MediaActionSound#START_VIDEO_RECORDING` The sound used by `https://developer.android.com/reference/android/media/MediaRecorder#start()` to indicate the start of video recording. |
| `int` | `https://developer.android.com/reference/android/media/MediaActionSound#STOP_VIDEO_RECORDING` The sound used by `https://developer.android.com/reference/android/media/MediaRecorder#stop()` to indicate the end of video recording. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/MediaActionSound#MediaActionSound()() ` Construct a new MediaActionSound instance. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/MediaActionSound#load(int)(int soundName) ` Preload a predefined platform sound to minimize latency when the sound is played later by `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`. |
| ` static boolean` | ` https://developer.android.com/reference/android/media/MediaActionSound#mustPlayShutterSound()() ` <br /> Returns true if the application must play the shutter sound in accordance to certain regional restrictions. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaActionSound#play(int)(int soundName) ` <br /> Play one of the predefined platform sounds for media actions. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaActionSound#release()() ` Free up all audio resources used by this MediaActionSound instance. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### FOCUS_COMPLETE

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FOCUS_COMPLETE
```

A sound to indicate that focusing has completed. Because deciding when this occurs is application-dependent, this sound is not used by any methods in the media or camera APIs.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`

Constant Value: 1 (0x00000001)

### SHUTTER_CLICK

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHUTTER_CLICK
```

The sound used by `https://developer.android.com/reference/android/hardware/Camera#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)` to indicate still image capture.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`

Constant Value: 0 (0x00000000)

### START_VIDEO_RECORDING

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int START_VIDEO_RECORDING
```

The sound used by `https://developer.android.com/reference/android/media/MediaRecorder#start()` to indicate the start of video recording.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`

Constant Value: 2 (0x00000002)

### STOP_VIDEO_RECORDING

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STOP_VIDEO_RECORDING
```

The sound used by `https://developer.android.com/reference/android/media/MediaRecorder#stop()` to indicate the end of video recording.

<br />

**See also:**

- `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`

Constant Value: 3 (0x00000003)

## Public constructors

### MediaActionSound

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MediaActionSound ()
```

Construct a new MediaActionSound instance. Only a single instance is needed for playing any platform media action sound; you do not need a separate instance for each sound type.

<br />

## Public methods

### load

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void load (int soundName)
```

Preload a predefined platform sound to minimize latency when the sound is played later by `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`.

<br />

| Parameters ||
|---|---|
| `soundName` | `int`: The type of sound to preload, selected from SHUTTER_CLICK, FOCUS_COMPLETE, START_VIDEO_RECORDING, or STOP_VIDEO_RECORDING. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/MediaActionSound#play(int)`
- `https://developer.android.com/reference/android/media/MediaActionSound#SHUTTER_CLICK`
- `https://developer.android.com/reference/android/media/MediaActionSound#FOCUS_COMPLETE`
- `https://developer.android.com/reference/android/media/MediaActionSound#START_VIDEO_RECORDING`
- `https://developer.android.com/reference/android/media/MediaActionSound#STOP_VIDEO_RECORDING`

### mustPlayShutterSound

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean mustPlayShutterSound ()
```

<br />

Returns true if the application must play the shutter sound in accordance to certain regional restrictions.

If this method returns true, applications are strongly recommended to use MediaActionSound.play(SHUTTER_CLICK) or START_VIDEO_RECORDING whenever it captures images or video to storage or sends them over the network.

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### play

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void play (int soundName)
```

<br />

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 `https://developer.android.com/reference/android/hardware/Camera#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)`, `https://developer.android.com/reference/android/media/MediaRecorder#start()`, and `https://developer.android.com/reference/android/media/MediaRecorder#stop()`.

With the `https://developer.android.com/reference/android/hardware/camera2/package-summary` API, this method can be used to play standard camera operation sounds with the appropriate system behavior for such sounds.

With the older `https://developer.android.com/reference/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 `https://developer.android.com/reference/android/media/MediaActionSound#load(int)` before calling play, play will load the sound at the cost of some additional latency before sound playback begins.

<br />

<br />

| Parameters ||
|---|---|
| `soundName` | `int`: The type of sound to play, selected from SHUTTER_CLICK, FOCUS_COMPLETE, START_VIDEO_RECORDING, or STOP_VIDEO_RECORDING. <br /> |

**See also:**

- `https://developer.android.com/reference/android/hardware/Camera#takePicture(android.hardware.Camera.ShutterCallback,%20android.hardware.Camera.PictureCallback,%20android.hardware.Camera.PictureCallback)`
- `https://developer.android.com/reference/android/media/MediaRecorder`
- `https://developer.android.com/reference/android/media/MediaActionSound#SHUTTER_CLICK`
- `https://developer.android.com/reference/android/media/MediaActionSound#FOCUS_COMPLETE`
- `https://developer.android.com/reference/android/media/MediaActionSound#START_VIDEO_RECORDING`
- `https://developer.android.com/reference/android/media/MediaActionSound#STOP_VIDEO_RECORDING`

### release

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void release ()
```

Free up all audio resources used by this MediaActionSound instance. Do not call any other methods on a MediaActionSound instance after calling release().

<br />