public class AudioPlayerTask
extends android.os.AsyncTask<java.lang.Void,java.lang.Void,java.lang.Void>
implements android.media.MediaPlayer.OnPreparedListener, android.media.MediaPlayer.OnErrorListener, android.media.MediaPlayer.OnCompletionListener
| Constructor and Description |
|---|
AudioPlayerTask(java.lang.String filePath,
CordovaInterface cordova,
CallbackContext callbackContext)
Initializing the mediaplayer
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Void |
doInBackground(java.lang.Void... arg0)
Perform playing the audio file in the background async
|
void |
onCompletion(android.media.MediaPlayer mp)
Destroy the mediaplayer when the audio file ends and then send
a success callback to JS
|
boolean |
onError(android.media.MediaPlayer mp,
int what,
int extra)
Destroy the mediaplayer and send an error callback to JS
|
void |
onPrepared(android.media.MediaPlayer mp)
When the mediaplayer is done with preparing async, the mediaplayer is ready for
playback and the task will be executed
and respectively the audio file will be played.
|
public AudioPlayerTask(java.lang.String filePath,
CordovaInterface cordova,
CallbackContext callbackContext)
filePath - The path of the audio filecordova - The cordova interface usedcallbackContext - The callback context used when calling back into JavaScriptpublic void onPrepared(android.media.MediaPlayer mp)
onPrepared in interface android.media.MediaPlayer.OnPreparedListenermp - The mediaplayer that has been prepared and ready for playbackpublic void onCompletion(android.media.MediaPlayer mp)
onCompletion in interface android.media.MediaPlayer.OnCompletionListenermp - The mediaplayer that plays the audio file and will be releasedpublic boolean onError(android.media.MediaPlayer mp,
int what,
int extra)
onError in interface android.media.MediaPlayer.OnErrorListenermp - The mediaplayer, which faced an errorwhat - Type of the error occurredextra - an extra code, specific to the errorprotected java.lang.Void doInBackground(java.lang.Void... arg0)
doInBackground in class android.os.AsyncTask<java.lang.Void,java.lang.Void,java.lang.Void>arg0 - No args