public class AsyncPlayer extends Object
Constructor and Description |
---|
AsyncPlayer(String tag)
Construct an AsyncPlayer object.
|
Modifier and Type | Method and Description |
---|---|
void |
play(Context context,
Uri uri,
boolean looping,
AudioAttributes attributes)
Start playing the sound.
|
void |
play(Context context,
Uri uri,
boolean looping,
int stream)
Deprecated.
use
play(Context, Uri, boolean, AudioAttributes) instead |
void |
setUsesWakeLock(Context context)
We want to hold a wake lock while we do the prepare and play.
|
void |
stop()
Stop a previously played sound.
|
public AsyncPlayer(String tag)
tag
- a string to use for debuggingpublic void play(Context context, Uri uri, boolean looping, int stream)
play(Context, Uri, boolean, AudioAttributes)
insteadcontext
- Your application's context.uri
- The URI to play. (see MediaPlayer.setDataSource(Context, Uri)
)looping
- Whether the audio should loop forever.
(see MediaPlayer.setLooping(boolean)
)stream
- the AudioStream to use.
(see MediaPlayer.setAudioStreamType(int)
)public void play(Context context, Uri uri, boolean looping, AudioAttributes attributes) throws IllegalArgumentException
context
- the non-null application's context.uri
- the non-null URI to play. (see MediaPlayer.setDataSource(Context, Uri)
)looping
- whether the audio should loop forever.
(see MediaPlayer.setLooping(boolean)
)attributes
- the non-null AudioAttributes
to use.
(see MediaPlayer.setAudioAttributes(AudioAttributes)
)IllegalArgumentException
public void stop()
public void setUsesWakeLock(Context context)