-
public class AudioPlayerAn AudioPlayer that uses the ExoPlayer as the backing architecture. If the current device does NOT pass the Android Compatibility Test Suite (CTS) then the backing architecture will fall back to using the default Android MediaPlayer.
To help with quick conversions from the Android MediaPlayer this class follows the APIs the Android MediaPlayer provides.
-
-
Constructor Summary
Constructors Constructor Description AudioPlayer(Context context)AudioPlayer(Context context, DeviceUtil deviceUtil)AudioPlayer(AudioPlayerApi audioPlayerImpl)
-
Method Summary
Modifier and Type Method Description intgetAudioSessionId()Returns the stream_ic_audio session ID. voidsetRepeatMode(int repeatMode)Sets the repeat mode for this MediaPlayer. booleansetPlaybackSpeed(float speed)Sets the playback speed for this MediaPlayer. floatgetPlaybackSpeed()Retrieves the current speed the media is playing at. voidsetAudioStreamType(int streamType)Sets the stream_ic_audio stream type for this MediaPlayer. voidsetDataSource(Uri uri)Sets the source path for the stream_ic_audio item. voidsetDataSource(Uri uri, MediaSource mediaSource)Sets the source path for the stream_ic_audio item. voidsetDrmCallback(MediaDrmCallback drmCallback)Sets the MediaDrmCallback to use when handling DRM for media. voidprepareAsync()Prepares the media specified with setDataSource or setDataSource in an asynchronous manner floatgetVolumeLeft()Retrieves the current left volume floatgetVolumeRight()Retrieves the current right volume voidsetVolume(float leftVolume, float rightVolume)Sets the volume level for the stream_ic_audio playback. voidsetWakeMode(Context context, int mode)Set the low-level power management behavior for this AudioPlayer. voidreset()Stops the current stream_ic_audio playback and resets the listener statesso that we receive the callbacks for events like onPrepared voidseekTo(long milliSeconds)Moves the current stream_ic_audio progress to the specified location.This method should only be called after the AudioPlayer isprepared. booleanisPlaying()Returns if an stream_ic_audio item is currently in playback voidstart()Starts the playback for the stream_ic_audio item specified in setDataSource. voidpause()If an stream_ic_audio item is currently in playback, it will be paused voidstopPlayback()If an stream_ic_audio item is currently in playback then the playback will be stopped voidrelease()Releases the resources associated with this media player longgetDuration()Retrieves the duration of the current stream_ic_audio item. voidoverrideDuration(long duration)Setting this will override the duration that the item may actually be. longgetCurrentPosition()Retrieves the current position of the stream_ic_audio playback. intgetBufferPercentage()Retrieves the current buffer percent of the stream_ic_audio item. WindowInfogetWindowInfo()Retrieves the information associated with the current com.google.android.exoplayer2.Timeline.Window used by the ExoPlayer backed implementation. booleantrackSelectionAvailable()Determines if the current video player implementation supportstrack selection for stream_ic_audio or video tracks. voidsetTrack(ExoMedia.RendererType trackType, int trackIndex)Changes to the track with trackIndexfor the specifiedtrackTypevoidsetTrack(ExoMedia.RendererType trackType, int groupIndex, int trackIndex)Changes to the track with trackIndexfor the specifiedtrackTypeintgetSelectedTrackIndex(ExoMedia.RendererType type, int groupIndex)Map<ExoMedia.RendererType, TrackGroupArray>getAvailableTracks()Retrieves a list of available tracks to select from. voidsetOnPreparedListener(OnPreparedListener listener)Sets the listener to inform of VideoPlayer prepared events voidsetOnCompletionListener(OnCompletionListener listener)Sets the listener to inform of VideoPlayer completion events voidsetOnBufferUpdateListener(OnBufferUpdateListener listener)Sets the listener to inform of VideoPlayer buffer update events voidsetOnSeekCompletionListener(OnSeekCompletionListener listener)Sets the listener to inform of VideoPlayer seek completion events voidsetOnErrorListener(OnErrorListener listener)Sets the listener to inform of playback errors voidsetMetadataListener(MetadataListener listener)Sets the listener to inform of ID3 metadata updates voidsetAnalyticsListener(AnalyticsListener listener)Sets the listener to inform of Analytics updates -
-
Constructor Detail
-
AudioPlayer
AudioPlayer(Context context)
-
AudioPlayer
AudioPlayer(Context context, DeviceUtil deviceUtil)
-
AudioPlayer
AudioPlayer(AudioPlayerApi audioPlayerImpl)
-
-
Method Detail
-
getAudioSessionId
int getAudioSessionId()
Returns the stream_ic_audio session ID.
-
setRepeatMode
void setRepeatMode(int repeatMode)
Sets the repeat mode for this MediaPlayer.Note: This will only change the ExoPlayer implementation
- Parameters:
repeatMode- The repeat mode to use
-
setPlaybackSpeed
boolean setPlaybackSpeed(float speed)
Sets the playback speed for this MediaPlayer.
- Parameters:
speed- The speed to play the media back at
-
getPlaybackSpeed
float getPlaybackSpeed()
Retrieves the current speed the media is playing at.
-
setAudioStreamType
void setAudioStreamType(int streamType)
Sets the stream_ic_audio stream type for this MediaPlayer. See AudioManager for a list of stream types. Must call this method before prepare() orprepareAsync() in order for the target stream type to become effectivethereafter.
- Parameters:
streamType- The stream_ic_audio stream type
-
setDataSource
void setDataSource(Uri uri)
Sets the source path for the stream_ic_audio item. This path can be a web address (e.g. http://) oran absolute local path (e.g. file://)
- Parameters:
uri- The Uri representing the path to the stream_ic_audio item
-
setDataSource
void setDataSource(Uri uri, MediaSource mediaSource)
Sets the source path for the stream_ic_audio item. This path can be a web address (e.g. http://) oran absolute local path (e.g. file://)
- Parameters:
uri- The Uri representing the path to the stream_ic_audio itemmediaSource- The MediaSource to use for stream_ic_audio playback
-
setDrmCallback
void setDrmCallback(MediaDrmCallback drmCallback)
Sets the MediaDrmCallback to use when handling DRM for media.This should be called before specifying the videos uri or pathNOTE: DRM is only supported on API 18 +
- Parameters:
drmCallback- The callback to use when handling DRM media
-
prepareAsync
void prepareAsync()
Prepares the media specified with setDataSource or setDataSource in an asynchronous manner
-
getVolumeLeft
float getVolumeLeft()
Retrieves the current left volume
-
getVolumeRight
float getVolumeRight()
Retrieves the current right volume
-
setVolume
void setVolume(float leftVolume, float rightVolume)
Sets the volume level for the stream_ic_audio playback.
- Parameters:
leftVolume- The volume range [0.0 - 1.rightVolume- The volume range [0.0 - 1.
-
setWakeMode
void setWakeMode(Context context, int mode)
Set the low-level power management behavior for this AudioPlayer.
This function has the AudioPlayer access the low-level power managerservice to control the device's power usage while playing is occurring.The parameter is a combination of android.os.PowerManager wake flags.Use of this method requires WAKE_LOCK permission.By default, no attempt is made to keep the device awake during playback.
- Parameters:
context- the Context to usemode- the power/wake mode to set
-
reset
void reset()
Stops the current stream_ic_audio playback and resets the listener statesso that we receive the callbacks for events like onPrepared
-
seekTo
void seekTo(long milliSeconds)
Moves the current stream_ic_audio progress to the specified location.This method should only be called after the AudioPlayer isprepared. (see setOnPreparedListener
- Parameters:
milliSeconds- The time to move the playback to
-
isPlaying
boolean isPlaying()
Returns if an stream_ic_audio item is currently in playback
-
start
void start()
Starts the playback for the stream_ic_audio item specified in setDataSource.This should be called after the AudioPlayer is correctly prepared (see setOnPreparedListener)
-
pause
void pause()
If an stream_ic_audio item is currently in playback, it will be paused
-
stopPlayback
void stopPlayback()
If an stream_ic_audio item is currently in playback then the playback will be stopped
-
release
void release()
Releases the resources associated with this media player
-
getDuration
long getDuration()
Retrieves the duration of the current stream_ic_audio item. This should only be called afterthe item is prepared (see setOnPreparedListener).If overrideDuration is set then that value will be returned.
-
overrideDuration
void overrideDuration(long duration)
Setting this will override the duration that the item may actually be. This method shouldonly be used when the item doesn't return the correct duration such as with stream_ic_audio streams.This only overrides the current stream_ic_audio item.
- Parameters:
duration- The duration for the current media item or < 0 to disable
-
getCurrentPosition
long getCurrentPosition()
Retrieves the current position of the stream_ic_audio playback. If an stream_ic_audio item is not currentlyin playback then the value will be 0. This should only be called after the item isprepared (see setOnPreparedListener)
-
getBufferPercentage
int getBufferPercentage()
Retrieves the current buffer percent of the stream_ic_audio item. If an stream_ic_audio item is not currentlyprepared or buffering the value will be 0. This should only be called after the stream_ic_audio item isprepared (see setOnPreparedListener)
-
getWindowInfo
@Nullable() WindowInfo getWindowInfo()
Retrieves the information associated with the current com.google.android.exoplayer2.Timeline.Window used by the ExoPlayer backed implementation. When the android.media.MediaPlayer backedimplementation is being used this will be null.
-
trackSelectionAvailable
boolean trackSelectionAvailable()
Determines if the current video player implementation supportstrack selection for stream_ic_audio or video tracks.
-
setTrack
@Deprecated() void setTrack(ExoMedia.RendererType trackType, int trackIndex)
Changes to the track with
trackIndexfor the specifiedtrackType- Parameters:
trackType- The type for the track to switch to the selected indextrackIndex- The index for the track to switch to
-
setTrack
void setTrack(ExoMedia.RendererType trackType, int groupIndex, int trackIndex)
Changes to the track with
trackIndexfor the specifiedtrackType- Parameters:
trackType- The type for the track to switch to the selected indexgroupIndex- The index for the group in the TrackGroupArray specified by thetrackTypetrackIndex- The index for the track to switch to
-
getSelectedTrackIndex
int getSelectedTrackIndex(ExoMedia.RendererType type, int groupIndex)
-
getAvailableTracks
@Nullable() Map<ExoMedia.RendererType, TrackGroupArray> getAvailableTracks()
Retrieves a list of available tracks to select from. Typically trackSelectionAvailable should be called before this.
-
setOnPreparedListener
void setOnPreparedListener(OnPreparedListener listener)
Sets the listener to inform of VideoPlayer prepared events
- Parameters:
listener- The listener
-
setOnCompletionListener
void setOnCompletionListener(OnCompletionListener listener)
Sets the listener to inform of VideoPlayer completion events
- Parameters:
listener- The listener
-
setOnBufferUpdateListener
void setOnBufferUpdateListener(OnBufferUpdateListener listener)
Sets the listener to inform of VideoPlayer buffer update events
- Parameters:
listener- The listener
-
setOnSeekCompletionListener
void setOnSeekCompletionListener(OnSeekCompletionListener listener)
Sets the listener to inform of VideoPlayer seek completion events
- Parameters:
listener- The listener
-
setOnErrorListener
void setOnErrorListener(OnErrorListener listener)
Sets the listener to inform of playback errors
- Parameters:
listener- The listener
-
setMetadataListener
void setMetadataListener(MetadataListener listener)
Sets the listener to inform of ID3 metadata updates
- Parameters:
listener- The listener to inform
-
setAnalyticsListener
void setAnalyticsListener(AnalyticsListener listener)
Sets the listener to inform of Analytics updates
- Parameters:
listener- The listener to inform
-
-
-
-