public class AudioPlayer
extends java.lang.Object
To help with quick conversions from the Android MediaPlayer this class follows the APIs the Android MediaPlayer provides.
| Modifier and Type | Field and Description |
|---|---|
protected AudioPlayerApi |
audioPlayerImpl |
protected ListenerMux |
listenerMux |
protected long |
overriddenDuration |
| Constructor and Description |
|---|
AudioPlayer(AudioPlayerApi audioPlayerImpl) |
AudioPlayer(android.content.Context context) |
AudioPlayer(android.content.Context context,
DeviceUtil deviceUtil) |
| Modifier and Type | Method and Description |
|---|---|
int |
getAudioSessionId()
Returns the audio session ID.
|
java.util.Map<ExoMedia.RendererType,TrackGroupArray> |
getAvailableTracks()
Retrieves a list of available tracks to select from.
|
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.
|
float |
getPlaybackSpeed()
Retrieves the current speed the media is playing at.
|
int |
getSelectedTrackIndex(ExoMedia.RendererType type,
int groupIndex) |
float |
getVolumeLeft()
Retrieves the current left volume
|
WindowInfo |
getWindowInfo()
Retrieves the information associated with the current
com.google.android.exoplayer2.Timeline.Window
used by the ExoPlayer backed implementation. |
protected void |
init(AudioPlayerApi audioPlayerImpl) |
boolean |
isPlaying()
Returns if an audio item is currently in playback
|
void |
overrideDuration(long duration)
Setting this will override the duration that the item may actually be.
|
void |
pause()
If an audio item is currently in playback, it will be paused
|
void |
prepareAsync()
Prepares the media specified with
setDataSource(Uri) or
setDataSource(Uri, MediaSource) in an asynchronous manner |
void |
release()
Releases the resources associated with this media player
|
void |
reset()
Stops the current audio playback and resets the listener states
so that we receive the callbacks for events like onPrepared
|
void |
seekTo(long milliSeconds)
Moves the current audio progress to the specified location.
|
void |
setAnalyticsListener(AnalyticsListener listener)
Sets the listener to inform of Analytics updates
|
void |
setAudioStreamType(int streamType)
Sets the audio stream type for this MediaPlayer.
|
void |
setDataSource(android.net.Uri uri)
Sets the source path for the audio item.
|
void |
setDataSource(android.net.Uri uri,
MediaSource mediaSource)
Sets the source path for the audio item.
|
void |
setDrmCallback(MediaDrmCallback drmCallback)
Sets the
MediaDrmCallback to use when handling DRM for media. |
void |
setMetadataListener(MetadataListener listener)
Sets the listener to inform of ID3 metadata updates
|
void |
setOnBufferUpdateListener(OnBufferUpdateListener listener)
Sets the listener to inform of VideoPlayer buffer update events
|
void |
setOnCompletionListener(OnCompletionListener listener)
Sets the listener to inform of VideoPlayer completion events
|
void |
setOnErrorListener(OnErrorListener listener)
Sets the listener to inform of playback errors
|
void |
setOnPreparedListener(OnPreparedListener listener)
Sets the listener to inform of VideoPlayer prepared events
|
void |
setOnSeekCompletionListener(OnSeekCompletionListener listener)
Sets the listener to inform of VideoPlayer seek completion events
|
boolean |
setPlaybackSpeed(float speed)
Sets the playback speed for this MediaPlayer.
|
void |
setRepeatMode(int repeatMode)
Sets the repeat mode for this MediaPlayer.
|
void |
setTrack(ExoMedia.RendererType trackType,
int trackIndex)
Deprecated.
|
void |
setTrack(ExoMedia.RendererType trackType,
int groupIndex,
int trackIndex)
Changes to the track with
trackIndex for the specified
trackType |
void |
setVolume(float leftVolume,
float rightVolume)
Sets the volume level for the audio playback.
|
void |
setWakeMode(android.content.Context context,
int mode)
Set the low-level power management behavior for this AudioPlayer.
|
void |
start()
Starts the playback for the audio item specified in
setDataSource(Uri). |
void |
stopPlayback()
If an audio item is currently in playback then the playback will be stopped
|
boolean |
trackSelectionAvailable()
Determines if the current video player implementation supports
track selection for audio or video tracks.
|
protected ListenerMux listenerMux
protected AudioPlayerApi audioPlayerImpl
protected long overriddenDuration
public AudioPlayer(android.content.Context context)
public AudioPlayer(android.content.Context context,
DeviceUtil deviceUtil)
public AudioPlayer(AudioPlayerApi audioPlayerImpl)
protected void init(AudioPlayerApi audioPlayerImpl)
public int getAudioSessionId()
public void setRepeatMode(int repeatMode)
repeatMode - The repeat mode to usepublic boolean setPlaybackSpeed(float speed)
speed - The speed to play the media back atpublic float getPlaybackSpeed()
public void setAudioStreamType(int streamType)
AudioManager
for a list of stream types. Must call this method before prepare() or
prepareAsync() in order for the target stream type to become effective
thereafter.streamType - The audio stream typeAudioManagerpublic void setDataSource(android.net.Uri uri)
uri - The Uri representing the path to the audio itempublic void setDataSource(android.net.Uri uri,
MediaSource mediaSource)
uri - The Uri representing the path to the audio itemmediaSource - The MediaSource to use for audio playbackpublic void setDrmCallback(MediaDrmCallback drmCallback)
MediaDrmCallback to use when handling DRM for media.
This should be called before specifying the videos uri or path
drmCallback - The callback to use when handling DRM mediapublic void prepareAsync()
setDataSource(Uri) or
setDataSource(Uri, MediaSource) in an asynchronous mannerpublic float getVolumeLeft()
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(android.content.Context context,
int mode)
This function has the AudioPlayer access the low-level power manager
service to control the device's power usage while playing is occurring.
The parameter is a combination of PowerManager wake flags.
Use of this method requires Manifest.permission.WAKE_LOCK
permission.
By default, no attempt is made to keep the device awake during playback.
context - the Context to usemode - the power/wake mode to setPowerManagerpublic void reset()
public void seekTo(long milliSeconds)
setOnPreparedListener(OnPreparedListener)milliSeconds - The time to move the playback topublic boolean isPlaying()
public void start()
setDataSource(Uri).
This should be called after the AudioPlayer is correctly prepared (see setOnPreparedListener(OnPreparedListener))public void pause()
public void stopPlayback()
public void release()
public long getDuration()
setOnPreparedListener(OnPreparedListener)).
If overrideDuration(long) is set then that value will be returned.public void overrideDuration(long duration)
duration - The duration for the current media item or < 0 to disablepublic long getCurrentPosition()
setOnPreparedListener(OnPreparedListener))public int getBufferPercentage()
setOnPreparedListener(OnPreparedListener))public WindowInfo getWindowInfo()
com.google.android.exoplayer2.Timeline.Window
used by the ExoPlayer backed implementation. When the MediaPlayer backed
implementation is being used this will be null.public boolean trackSelectionAvailable()
@Deprecated public void setTrack(ExoMedia.RendererType trackType, int trackIndex)
setTrack(ExoMedia.RendererType, int, int)trackIndex for the specified
trackTypetrackType - The type for the track to switch to the selected indextrackIndex - The index for the track to switch topublic void setTrack(ExoMedia.RendererType trackType, int groupIndex, int trackIndex)
trackIndex for the specified
trackTypetrackType - The type for the track to switch to the selected indexgroupIndex - The index for the group in the TrackGroupArray specified by the trackTypetrackIndex - The index for the track to switch topublic int getSelectedTrackIndex(ExoMedia.RendererType type, int groupIndex)
public java.util.Map<ExoMedia.RendererType,TrackGroupArray> getAvailableTracks()
trackSelectionAvailable()
should be called before this.public void setOnPreparedListener(OnPreparedListener listener)
listener - The listenerpublic void setOnCompletionListener(OnCompletionListener listener)
listener - The listenerpublic void setOnBufferUpdateListener(OnBufferUpdateListener listener)
listener - The listenerpublic void setOnSeekCompletionListener(OnSeekCompletionListener listener)
listener - The listenerpublic void setOnErrorListener(OnErrorListener listener)
listener - The listenerpublic void setMetadataListener(MetadataListener listener)
listener - The listener to informpublic void setAnalyticsListener(AnalyticsListener listener)
listener - The listener to inform