public final class AudioPlayer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TAG |
Constructor and Description |
---|
AudioPlayer(Context context)
Audio player constructor
|
AudioPlayer(Context context,
java.lang.String audioFile,
OnPlayListener listener)
Audio player constructor
|
Modifier and Type | Method and Description |
---|---|
long |
getCurrentPosition()
Get the current position of the playback
|
long |
getDuration()
Get the duration of an audio file
|
OnPlayListener |
getOnPlayListener() |
boolean |
isPlaying()
Check if the player is playing
|
void |
seekTo(int msec)
Seek to a specified position for playback.
|
void |
setDataSource(java.lang.String audioFile)
Set the audio source
|
void |
setOnPlayListener(OnPlayListener listener)
Set a listener for playback
|
void |
start(int audioStreamType)
Starts playing the video file.
|
void |
stop()
Stop playback
|
public static final java.lang.String TAG
public AudioPlayer(Context context)
context
- The contextpublic AudioPlayer(Context context, java.lang.String audioFile, OnPlayListener listener)
context
- The contextaudioFile
- The path of the audio file for playbacklistener
- The listener for playback progresspublic void setDataSource(java.lang.String audioFile)
audioFile
- The path of the audio file for playbackpublic void setOnPlayListener(OnPlayListener listener)
listener
- public OnPlayListener getOnPlayListener()
public void start(int audioStreamType)
audioStreamType
- The audio stream type used to switch between headset and earpieces. For information about values, see android.media.AudioManagerpublic void stop()
public boolean isPlaying()
public long getDuration()
public long getCurrentPosition()
public void seekTo(int msec)
msec
- The specified playback position. Unit: milliseconds