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

# AsyncPlayer

*** ** * ** ***

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

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

<br />

*** ** * ** ***

Plays a series of audio URIs, but does all the hard work on another thread so that any slowness with preparing or loading doesn't block the calling thread.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/AsyncPlayer#AsyncPlayer(java.lang.String)(https://developer.android.com/reference/java/lang/String tag) ` Construct an AsyncPlayer object. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/AsyncPlayer#play(android.content.Context,%20android.net.Uri,%20boolean,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/net/Uri uri, boolean looping, int stream) ` *This method was deprecated in API level 23. use `https://developer.android.com/reference/android/media/AsyncPlayer#play(android.content.Context,%20android.net.Uri,%20boolean,%20android.media.AudioAttributes)` instead* |
| ` void` | ` https://developer.android.com/reference/android/media/AsyncPlayer#play(android.content.Context,%20android.net.Uri,%20boolean,%20android.media.AudioAttributes)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/net/Uri uri, boolean looping, https://developer.android.com/reference/android/media/AudioAttributes attributes) ` Start playing the sound. |
| ` void` | ` https://developer.android.com/reference/android/media/AsyncPlayer#stop()() ` Stop a previously played sound. |

### 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*.

## Public constructors

### AsyncPlayer

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

```
public AsyncPlayer (String tag)
```

Construct an AsyncPlayer object.

<br />

| Parameters ||
|---|---|
| `tag` | `String`: a string to use for debugging <br /> |

## Public methods

### play

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

```
public void play (Context context, 
                Uri uri, 
                boolean looping, 
                int stream)
```

<br />

**This method was deprecated in API level 23.**   

use `https://developer.android.com/reference/android/media/AsyncPlayer#play(android.content.Context,%20android.net.Uri,%20boolean,%20android.media.AudioAttributes)` instead

Start playing the sound. It will actually start playing at some point in the future. There are no guarantees about latency here. Calling this before another audio file is done playing will stop that one and start the new one.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: Your application's context. <br /> |
| `uri` | `Uri`: The URI to play. (see `https://developer.android.com/reference/android/media/MediaPlayer#setDataSource(android.content.Context,%20android.net.Uri)`) <br /> |
| `looping` | `boolean`: Whether the audio should loop forever. (see `https://developer.android.com/reference/android/media/MediaPlayer#setLooping(boolean)`) <br /> |
| `stream` | `int`: the AudioStream to use. (see `https://developer.android.com/reference/android/media/MediaPlayer#setAudioStreamType(int)`) <br /> |

### play

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

```
public void play (Context context, 
                Uri uri, 
                boolean looping, 
                AudioAttributes attributes)
```

Start playing the sound. It will actually start playing at some point in the future. There are no guarantees about latency here. Calling this before another audio file is done playing will stop that one and start the new one.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the non-null application's context. <br /> |
| `uri` | `Uri`: the non-null URI to play. (see `https://developer.android.com/reference/android/media/MediaPlayer#setDataSource(android.content.Context,%20android.net.Uri)`) <br /> |
| `looping` | `boolean`: whether the audio should loop forever. (see `https://developer.android.com/reference/android/media/MediaPlayer#setLooping(boolean)`) <br /> |
| `attributes` | `AudioAttributes`: the non-null `https://developer.android.com/reference/android/media/AudioAttributes` to use. (see `https://developer.android.com/reference/android/media/MediaPlayer#setAudioAttributes(android.media.AudioAttributes)`) <br /> |

| Throws ||
|---|---|
|   | java.lang.IllegalArgumentException |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` |   |

### stop

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

```
public void stop ()
```

Stop a previously played sound. It can't be played again or unpaused at this point. Calling this multiple times has no ill effects.

<br />