public class EMAudioPlayer
extends java.lang.Object
implements com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.Listener
To help with quick conversions from the Android MediaPlayer this class follows the APIs the MediaPlayer provides.
Modifier and Type | Class and Description |
---|---|
static class |
EMAudioPlayer.AudioType |
Constructor and Description |
---|
EMAudioPlayer(Context context) |
Modifier and Type | Method and Description |
---|---|
void |
addExoPlayerListener(ExoPlayerListener listener)
Sets the listener to inform of any exoPlayer events
|
int |
getAudioSessionId()
Returns the audio session ID.
|
int |
getBufferPercentage()
Retrieves the current buffer percent of the audio item.
|
long |
getCurrentPosition()
Retrieves the current position of the audio playback.
|
long |
getDuration()
Retrieves the duration of the current audio item.
|
java.lang.String |
getUserAgent()
Retrieves the user agent that the EMAudioPlayer will use when communicating
with media servers
|
boolean |
isPlaying()
Returns if an audio item is currently in playback
|
void |
onAudioCapabilitiesChanged(com.google.android.exoplayer.audio.AudioCapabilities audioCapabilities) |
void |
overrideDuration(int duration)
Setting this will override the duration that the item may actually be.
|
void |
overridePosition(boolean override)
Sets if the audio position should be overridden, allowing the time to be restarted at will.
|
void |
pause()
If an audio item is currently in playback, it will be paused and the progressPoll
will be stopped (see
startProgressPoll(EMEventBus) ) |
void |
prepareAsync() |
void |
release() |
void |
removeExoPlayerListener(ExoPlayerListener listener)
Removes the specified listener for the ExoPlayer.
|
void |
reset()
Stops the current audio playback and resets the listener states
so that we receive the callbacks for events like onPrepared
|
void |
restartOverridePosition()
Restarts the audio position to the start if the position is being overridden (see
overridePosition(boolean) ). |
void |
seekTo(int milliSeconds)
Moves the current audio progress to the specified location.
|
void |
setAudioStreamType(int steamType) |
void |
setBus(EMEventBus bus)
Sets the bus to use for dispatching Events such as the poll progress
|
void |
setDataSource(Context context,
Uri uri)
Sets the source path for the audio item.
|
void |
setDataSource(Context context,
Uri uri,
MediaUtil.MediaType defaultMediaType)
Sets the source path for the audio item.
|
void |
setOnBufferingUpdateListener(android.media.MediaPlayer.OnBufferingUpdateListener listener)
Sets the listener to inform of buffering updates
|
void |
setOnCompletionListener(MediaPlayer.OnCompletionListener listener)
Sets the listener to inform of VideoPlayer completion events.
|
void |
setOnErrorListener(MediaPlayer.OnErrorListener listener)
Sets the listener to inform of playback errors.
|
void |
setOnInfoListener(MediaPlayer.OnInfoListener listener)
Sets the listener to inform of media information events.
|
void |
setOnPreparedListener(MediaPlayer.OnPreparedListener listener)
Sets the listener to inform of VideoPlayer prepared events.
|
void |
setPositionOffset(int offset)
Sets the amount of time to change the return value from
getCurrentPosition() . |
void |
setProgressPollDelay(int milliSeconds)
Sets the delay to use when notifying of progress.
|
void |
setVolume(float leftVolume,
float rightVolume)
Sets the volume level for the audio playback.
|
void |
setWakeMode(Context context,
int mode) |
void |
start()
Starts the playback for the audio item specified in
#setDataSource(android.content.Context, android.net.Uri) . |
void |
startProgressPoll(EMEventBus bus)
Starts the progress poll.
|
void |
startProgressPoll(EMProgressCallback callback)
Starts the progress poll with the callback to be informed of the progress
events.
|
void |
stopPlayback()
If an audio item is currently in playback then the playback will be stopped
and the progressPoll will be stopped (see
startProgressPoll(EMEventBus) ) |
void |
stopProgressPoll()
Stops the progress poll
(see
startProgressPoll(EMEventBus) ) |
public void onAudioCapabilitiesChanged(com.google.android.exoplayer.audio.AudioCapabilities audioCapabilities)
onAudioCapabilitiesChanged
in interface com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.Listener
public void setProgressPollDelay(int milliSeconds)
milliSeconds
- The millisecond delay to usepublic void setBus(EMEventBus bus)
bus
- The EventBus to dispatch events onpublic void startProgressPoll(EMEventBus bus)
bus
- The EventBus event dispatcher that the listener is connected topublic void startProgressPoll(EMProgressCallback callback)
callback
- The Callback to inform of progress eventspublic void stopProgressPoll()
startProgressPoll(EMEventBus)
)public java.lang.String getUserAgent()
public int getAudioSessionId()
public void setAudioStreamType(int steamType)
public void setDataSource(Context context, Uri uri)
context
- The applications context that owns the mediauri
- The Uri representing the path to the audio itempublic void setDataSource(Context context, Uri uri, MediaUtil.MediaType defaultMediaType)
context
- The applications context that owns the mediauri
- The Uri representing the path to the audio itemdefaultMediaType
- The MediaType to use when auto-detection failspublic void prepareAsync()
public void setVolume(float leftVolume, float rightVolume)
leftVolume
- The volume range [0.0 - 1.0]rightVolume
- The volume range [0.0 - 1.0]public void setWakeMode(Context context, int mode)
public void reset()
public void seekTo(int milliSeconds)
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
milliSeconds
- The time to move the playback topublic boolean isPlaying()
public void start()
#setDataSource(android.content.Context, android.net.Uri)
.
This should be called after the AudioPlayer is correctly prepared (see #setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
)public void pause()
startProgressPoll(EMEventBus)
)public void stopPlayback()
startProgressPoll(EMEventBus)
)public void release()
public long getDuration()
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
).
If overrideDuration(int)
is set then that value will be returned.public void overrideDuration(int duration)
duration
- The duration for the current media item or < 0 to disablepublic long getCurrentPosition()
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
)public void setPositionOffset(int offset)
getCurrentPosition()
.
This value will be reset when a new audio item is selected.offset
- The millisecond value to offset the positionpublic void restartOverridePosition()
overridePosition(boolean)
).
This will be the value specified with setPositionOffset(int)
or 0 if it hasn't been set.public void overridePosition(boolean override)
override
- True if the position should be overriddenpublic int getBufferPercentage()
#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)
)public void addExoPlayerListener(ExoPlayerListener listener)
listener
- The listenerpublic void removeExoPlayerListener(ExoPlayerListener listener)
listener
- The listener to removepublic void setOnPreparedListener(MediaPlayer.OnPreparedListener listener)
EMMediaPreparedEvent
listener
- The listenerpublic void setOnCompletionListener(MediaPlayer.OnCompletionListener listener)
EMMediaCompletionEvent
listener
- The listenerpublic void setOnErrorListener(MediaPlayer.OnErrorListener listener)
EMMediaErrorEvent
listener
- The listenerpublic void setOnInfoListener(MediaPlayer.OnInfoListener listener)
listener
- The listenerpublic void setOnBufferingUpdateListener(android.media.MediaPlayer.OnBufferingUpdateListener listener)
listener
- The listener