public class NativeAudioPlayer extends java.lang.Object implements AudioPlayerApi
ListenerMux and to mitigate state errors.
NOTE: The listenerMux shouldn't be null when any
method utilizing it is called, however there are some cases on
Amazon devices where they incorrectly call these methods when
setting up the MediaPlayer (when in IDLE state)
| Modifier and Type | Class and Description |
|---|---|
protected class |
NativeAudioPlayer.InternalListeners |
| Modifier and Type | Field and Description |
|---|---|
protected android.content.Context |
context |
protected int |
currentBufferPercent |
protected NativeAudioPlayer.InternalListeners |
internalListeners |
protected ListenerMux |
listenerMux |
protected android.media.MediaPlayer |
mediaPlayer |
protected long |
requestedSeek |
| Constructor and Description |
|---|
NativeAudioPlayer(android.content.Context context) |
| Modifier and Type | Method and Description |
|---|---|
int |
getAudioSessionId() |
java.util.Map<ExoMedia.RendererType,com.google.android.exoplayer2.source.TrackGroupArray> |
getAvailableTracks()
Retrieves a list of available tracks to select from.
|
int |
getBufferedPercent() |
long |
getCurrentPosition() |
long |
getDuration() |
boolean |
isPlaying() |
void |
onMediaPrepared() |
void |
pause() |
void |
prepareAsync()
Prepares the media specified with
AudioPlayerApi.setDataSource(Uri) or
AudioPlayerApi.setDataSource(Uri, MediaSource) in an asynchronous manner |
void |
release()
Releases the resources associated with this media player
|
void |
reset() |
boolean |
restart()
Prepares the media previously specified for playback.
|
void |
seekTo(long milliseconds) |
void |
setAudioStreamType(int streamType)
Sets the audio stream type for this MediaPlayer.
|
void |
setDataSource(android.net.Uri uri) |
void |
setDataSource(android.net.Uri uri,
com.google.android.exoplayer2.source.MediaSource mediaSource) |
void |
setDrmCallback(com.google.android.exoplayer2.drm.MediaDrmCallback drmCallback)
Sets the
MediaDrmCallback to use when handling DRM for media. |
void |
setListenerMux(ListenerMux listenerMux) |
boolean |
setPlaybackSpeed(float speed)
Sets the playback speed for this MediaPlayer.
|
void |
setTrack(ExoMedia.RendererType trackType,
int trackIndex) |
void |
setVolume(float left,
float right) |
void |
setWakeMode(android.content.Context context,
int mode) |
void |
start() |
void |
stopPlayback() |
boolean |
trackSelectionAvailable() |
@NonNull protected final android.content.Context context
@NonNull protected final android.media.MediaPlayer mediaPlayer
@NonNull protected NativeAudioPlayer.InternalListeners internalListeners
protected ListenerMux listenerMux
protected long requestedSeek
protected int currentBufferPercent
public NativeAudioPlayer(@NonNull
android.content.Context context)
public void setDataSource(@Nullable
android.net.Uri uri)
setDataSource in interface AudioPlayerApipublic void setDataSource(@Nullable
android.net.Uri uri,
@Nullable
com.google.android.exoplayer2.source.MediaSource mediaSource)
setDataSource in interface AudioPlayerApipublic void setDrmCallback(@Nullable
com.google.android.exoplayer2.drm.MediaDrmCallback drmCallback)
AudioPlayerApiMediaDrmCallback to use when handling DRM for media.
This should be called before specifying the videos uri or path
setDrmCallback in interface AudioPlayerApidrmCallback - The callback to use when handling DRM mediapublic void prepareAsync()
AudioPlayerApiAudioPlayerApi.setDataSource(Uri) or
AudioPlayerApi.setDataSource(Uri, MediaSource) in an asynchronous mannerprepareAsync in interface AudioPlayerApipublic void reset()
reset in interface AudioPlayerApipublic void setVolume(float left,
float right)
setVolume in interface AudioPlayerApipublic void seekTo(long milliseconds)
seekTo in interface AudioPlayerApipublic boolean isPlaying()
isPlaying in interface AudioPlayerApipublic void start()
start in interface AudioPlayerApipublic void pause()
pause in interface AudioPlayerApipublic void stopPlayback()
stopPlayback in interface AudioPlayerApipublic boolean restart()
AudioPlayerApirestart in interface AudioPlayerApitrue if the media was successfully restartedpublic long getDuration()
getDuration in interface AudioPlayerApipublic long getCurrentPosition()
getCurrentPosition in interface AudioPlayerApipublic int getBufferedPercent()
getBufferedPercent in interface AudioPlayerApipublic void release()
AudioPlayerApirelease in interface AudioPlayerApipublic int getAudioSessionId()
getAudioSessionId in interface AudioPlayerApipublic boolean setPlaybackSpeed(float speed)
AudioPlayerApisetPlaybackSpeed in interface AudioPlayerApispeed - The speed to play the media back atpublic void setAudioStreamType(int streamType)
AudioPlayerApiAudioManager
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.setAudioStreamType in interface AudioPlayerApistreamType - The audio stream typeAudioManagerpublic void setWakeMode(android.content.Context context,
int mode)
setWakeMode in interface AudioPlayerApipublic boolean trackSelectionAvailable()
trackSelectionAvailable in interface AudioPlayerApipublic void setTrack(ExoMedia.RendererType trackType, int trackIndex)
setTrack in interface AudioPlayerApi@Nullable public java.util.Map<ExoMedia.RendererType,com.google.android.exoplayer2.source.TrackGroupArray> getAvailableTracks()
AudioPlayerApiAudioPlayerApi.trackSelectionAvailable()
should be called before this.getAvailableTracks in interface AudioPlayerApipublic void setListenerMux(ListenerMux listenerMux)
setListenerMux in interface AudioPlayerApipublic void onMediaPrepared()
onMediaPrepared in interface AudioPlayerApi