Package 

Class AudioPlayer


  • 
    public class AudioPlayer
    
                        

    An 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.

    • Method Detail

      • 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 item
        mediaSource - 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
      • 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 use
        mode - 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

      • 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

      • 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 trackIndex for the specifiedtrackType

        Parameters:
        trackType - The type for the track to switch to the selected index
        trackIndex - The index for the track to switch to
      • setTrack

         void setTrack(ExoMedia.RendererType trackType, int groupIndex, int trackIndex)

        Changes to the track with trackIndex for the specifiedtrackType

        Parameters:
        trackType - The type for the track to switch to the selected index
        groupIndex - The index for the group in the TrackGroupArray specified by the trackType
        trackIndex - The index for the track to switch to
      • setAnalyticsListener

         void setAnalyticsListener(AnalyticsListener listener)

        Sets the listener to inform of Analytics updates

        Parameters:
        listener - The listener to inform