AdaptrPlayer

class AdaptrPlayer

Adaptr Media client that retrieves music from the Adaptr servers and plays them on the local device. The player can be assigned either an on demand AudioFile from search or playlists/Stations or an active station from list of online stationList or offline localOfflineStationList stations using play.

To make sure the music begins when requested user should call prepareToPlay before calling play

The player exposes its current State to assist with rendering playback state.

Player methods are almost all asynchronous, and the player makes heavy use of Listener classes to allow clients to monitor events and changes in the player state.

In most use cases, the player isn't useful until it has successfully contacted the Adaptr servers to retrieve a list of available streaming stations, and the AvailabilityListener helps with determining when music becomes available or playback.

Constructors

AdaptrPlayer
Link copied to clipboard
fun AdaptrPlayer(context: Context, token: String, secret: String)

Create an instance of the player.

AdaptrPlayer
Link copied to clipboard
fun AdaptrPlayer(context: Context, token: String, secret: String, availabilityListener: AvailabilityListener)

Create a new instance of the player, and register an AvailabilityListener to receive notice when the Adaptr servers have been contacted and streaming music is found to be available or not.

AdaptrPlayer
Link copied to clipboard
fun AdaptrPlayer(context: Context, token: String, secret: String, availabilityListener: AvailabilityListener, mockLocation: MockLocations)

Create a new instance of the player with an AvailabilityListener, and optionally ensure all player methods run in a background thread.

Types

Builder
Link copied to clipboard
class Builder(context: Context, token: String, secret: String)

This builder is a convenience class to reduce the number of parameters needed to construct a FeedAudioPlayer.

Companion
Link copied to clipboard
object Companion
ConnectionStateMonitor
Link copied to clipboard
inner class ConnectionStateMonitor : ConnectivityManager.NetworkCallback
MusicSource
Link copied to clipboard
enum MusicSource : Enum<AdaptrPlayer.MusicSource>

Functions

addAudioFocusListener
Link copied to clipboard
fun addAudioFocusListener(audioFocusListener: AudioFocusListener)
addAvailabilityListener
Link copied to clipboard
fun addAvailabilityListener(eventListener: AvailabilityListener)

Register an AvailabilityListener to be notified when music is determined to be available or not.

addLikeStatusChangeListener
Link copied to clipboard
fun addLikeStatusChangeListener(likeStatusChangeListener: LikeStatusChangeListener)

Register a LikeStatusChangeListener to be notified when the like status of song change.

addMusicQueuedListener
Link copied to clipboard
fun addMusicQueuedListener(musicQueuedListener: MusicQueuedListener?)

Register a MusicQueuedListener to receive notice when music is queued in the current station for immediate playback.

addOutOfMusicListener
Link copied to clipboard
fun addOutOfMusicListener(outOfMusicListener: OutOfMusicListener)

Add OutOfMusicListener

addPlayListener
Link copied to clipboard
fun addPlayListener(playListener: PlayListener)

Register a new PlayListener to receive notice when songs start, elapse, or have their skippability change.

addSkipListener
Link copied to clipboard
fun addSkipListener(eventListener: SkipListener)

Register a SkipListener to receive notice when a skip succeeds or fails.

addStateListener
Link copied to clipboard
fun addStateListener(stateListener: StateListener)

Add StateListener to the player

addStationChangedListener
Link copied to clipboard
fun addStationChangedListener(stationChangedListener: StationChangedListener)

Register a StationChangedListener to receive notice of change in the player's current active station.

addUnhandledErrorListener
Link copied to clipboard
fun addUnhandledErrorListener(eventListener: UnhandledErrorListener)

Register an UnhandledErrorListener to receive notice of errors that the player doesn't know how deal with.

canSkip
Link copied to clipboard
fun canSkip(): Boolean

When true, the player will be able to skip the current song instantly when skip() is called. If this is false the player may still be able to skip but it needs to be confirmed by the server. s

createNewClientId
Link copied to clipboard
fun createNewClientId(listener: ClientIdListener?)

Ask the Adaptr servers for a new client id for this device, then set that to the current and default client id via setClientId, then inform the provided listener what the new client id is.

createUserPlaylist
Link copied to clipboard
fun createUserPlaylist(name: String, playlist: List<AudioFile>): PlayList

Create a playlist from a collection of audio files. Call Save on editor to save the playlist to the server.

deleteAllOfflineStations
Link copied to clipboard
fun deleteAllOfflineStations()

Delete any and all locally stored audio files.

deleteOfflineStation
Link copied to clipboard
fun deleteOfflineStation(station: Station)

Delete all locally stored audio files from the given station.

deletePlaylist
Link copied to clipboard
fun deletePlaylist(playlist: PlayList)

Delete a previously saved playlist.

destroyInstance
Link copied to clipboard
fun destroyInstance()

Safely Destroys this instance of FeedAudioPlayer and frees up any resources it is using. If you have a reference to this object it should be set to null and a new instance should be created via initialize the next time music is to be played.

dislike
Link copied to clipboard
fun dislike()

Dislike the currently playing song and skip past it.

fun dislike(audioFile: AudioFile?)

Dislike the given audio file. If the song is the currently active song, it will be skipped.

downloadAndSync
Link copied to clipboard
fun downloadAndSync(station: Station, downloadListener: StationDownloadListener)

Downloads or updates an offline station.

fun downloadAndSync(targetMins: Int, station: Station, downloadListener: StationDownloadListener)

Download or update an offline station, but with an extra hint to the server as to the number of minutes of music that the client wants to be downloaded. This can be used to prevent a station with, say, 600 minutes, from being completely downloaded in a single call. If the given station already has content stored on the device, the server determines whether or not the client will 1) download any music,

favorite
Link copied to clipboard
fun favorite(audioFile: AudioFile)

favorite an audiofile

getFavorites
Link copied to clipboard
fun getFavorites(pageNo: Int, noPerPage: Int, listener: ResultsListener)

Get Favorite tacks for the user

getPlayQueue
Link copied to clipboard
fun getPlayQueue(): List<AudioFile>

Get the playlist to view the play queue

getSavedPlaylists
Link copied to clipboard
fun getSavedPlaylists(trackListener: PlaylistsListener)

Retrieve All previously saved playlists by the user. If the listener returns null no playlists were found

like
Link copied to clipboard
fun like()

Like the currently playing song

fun like(audioFile: AudioFile?)

Like the given audio file

logEvent
Link copied to clipboard
fun logEvent(event: String)

Log an event to the Adaptr servers

fun logEvent(event: String, params: Any)

Log event with parameters to the Adaptr service. The parameters can be generic object types, or Map or List or Array of those types.

maxSeekableLengthInSeconds
Link copied to clipboard
fun maxSeekableLengthInSeconds(): Float

Returns max no of seconds that a station can skip, usually between 300 to 700 seconds

pause
Link copied to clipboard
fun pause()

Pause music playback

play
Link copied to clipboard
fun play()

Start music playback. Will begin playback if there is any music in the queue. This should only be called to resume music playback. The music should be set using overloads of play. Even if prepareToPlay() has been called earlier, the music may or may not start immediately when this function is called. To be sure that playback will start when this function is called, user should wait for onPlayItemReadyForPlayback callback in MusicQueuedListener before calling this function.

fun play(audioFile: AudioFile, withCrossfade: Boolean = false)

Begin playback of a specific onDemand song.

fun play(station: Station, withCrossfade: Boolean = false)

Play the given station, with optional crossfade between the current song and the song in the new station.

fun play(audioFiles: List<AudioFile>, startIndex: Int = 0, withCrossfade: Boolean = false)

Begin playback of on Demand list.

prepareStations
Link copied to clipboard
fun prepareStations(stations: List<Station>, listener: CachePreparedListener? = null)

Tell the player that the given list of stations are expected to be imminently streamed, so that it can try to perform network operations ahead of time.

prepareToPlay
Link copied to clipboard
fun prepareToPlay(audioFile: AudioFile, listener: MusicQueuedListener? = null)

Register a MusicQueuedListener to be notified when the given is queued up for immediate playback upon calling play.

fun prepareToPlay(station: Station?, listener: MusicQueuedListener?)

Register a MusicQueuedListener to be notified when a song is queued up for immediate playback upon calling play.

previous
Link copied to clipboard
fun previous()

Go back to the previous tracks in the current playlist

removeAudioFocusListener
Link copied to clipboard
fun removeAudioFocusListener(audioFocusListener: AudioFocusListener)
removeLikeStatusChangeListener
Link copied to clipboard
fun removeLikeStatusChangeListener(likeStatusChangeListener: LikeStatusChangeListener)

Remove previously registered LikeStatusChangeListener

removeMusicQueuedListener
Link copied to clipboard
fun removeMusicQueuedListener(musicQueuedListener: MusicQueuedListener)

Remove a previously registered MusicQueuedListener from the player.

removeOutOfMusicListener
Link copied to clipboard
fun removeOutOfMusicListener(outOfMusicListener: OutOfMusicListener)

Remove previously registered OutOfMusicListener

removePlayListener
Link copied to clipboard
fun removePlayListener(playListener: PlayListener)

Remove a previously registered PlayListener from the player

removeSkipListener
Link copied to clipboard
fun removeSkipListener(eventListener: SkipListener)

Remove previously registered SkipListener

removeStateListener
Link copied to clipboard
fun removeStateListener(stateListener: StateListener)

Remove previously registered StateListener from the player

removeStationChangedListener
Link copied to clipboard
fun removeStationChangedListener(stationChangedListener: StationChangedListener)

Remove StationChangedListener from the player

removeUnhandledErrorListener
Link copied to clipboard
fun removeUnhandledErrorListener(eventListener: UnhandledErrorListener)

Remove previously registered UnhandledErrorListener

requestAudioFilesForPlaylist
Link copied to clipboard
fun requestAudioFilesForPlaylist(id: String, trackListener: PlaylistTrackListener)

Get tracks for an empty playlist previously save to server. if the listener returns null there were no tracks to be fetched.

requestAudioFilesForStation
Link copied to clipboard
fun requestAudioFilesForStation(stationid: Int, pageNo: Int = 0, resultsPerPage: Int = 20, listener: ResultsListener)

Request files for a Station

restart
Link copied to clipboard
fun restart()
searchMusic
Link copied to clipboard
fun searchMusic(query: String, listener: ResultsListener, pageNo: Int = 0, resultsPerPage: Int = 10, station: Station? = null)

Search the current placement for music related to a search term, results will be delivered to the listener. If the results will be playable using (play)

seek
Link copied to clipboard
fun seek(position: Float)

Seek to a new playback position of current track if seeking is allowed on the given file.

seekCurrentStationBy
Link copied to clipboard
fun seekCurrentStationBy(seconds: Float)

Seek the current station by this no of seconds.

setActiveStation
Link copied to clipboard
fun setActiveStation(station: Station, withCrossfade: Boolean)

Change station to the given one, with optional crossfade between the current song and the song in the new station.

setClientId
Link copied to clipboard
fun setClientId(exportedClientId: String): Boolean

Update the player's client id to a value previously returned from clientId, effectively changing the identity of current music listener.

setPlayer
Link copied to clipboard
fun setPlayer(player: MixingAudioPlayer)

Set a new mixing audio player.

setVolume
Link copied to clipboard
fun setVolume(volume: Float)

Set volume in relation to system volume

skip
Link copied to clipboard
fun skip()

Request skip on the currently playing song

fun skip(skipListener: SkipListener?)
stop
Link copied to clipboard
fun stop()

Stop music playback and remove any buffered audio from memory.

submitLogsForRemoteDebuggingWithLabel
Link copied to clipboard
fun submitLogsForRemoteDebuggingWithLabel(msg: String)

Trigger this method to send the logs of the current session to Adaptr servers

switchToDefaultPlayer
Link copied to clipboard
fun switchToDefaultPlayer()

Switch back to default Mixingplayer.

unfavorite
Link copied to clipboard
fun unfavorite(audioFile: AudioFile)

Unfavourite a previously favorited audiofile

unlike
Link copied to clipboard
fun unlike()

Mark the current song as neither liked nor disliked.

fun unlike(audioFile: AudioFile?)

Mark the given song as neither liked nor disliked.

updateSession
Link copied to clipboard
fun updateSession(listener: SessionUpdateListener)

Properties

activeStation
Link copied to clipboard
var activeStation: Station?

The currently active station from which music is or will be pulled from. This value will not be null as long as the player has access to music.

artWork
Link copied to clipboard
var artWork: Bitmap? = null

Artwork associated with the current station or song, if available. This value may change when the current song or station changes.

bIsSkipping
Link copied to clipboard
var bIsSkipping: Boolean = false

Request skip on the currently playing song, and provide a SkipListener to receive notice if the skip succeeded or failed.

bIsUpdatingSession
Link copied to clipboard
var bIsUpdatingSession: Boolean = false
clientId
Link copied to clipboard
val clientId: String?

Return the current unique client id so that it can be externally persisted or synchronized across devices and later passed to setClientId or Builder.setClientId.

currentPlay
Link copied to clipboard
val currentPlay: Play?

Get currently playing song or null if no song is playing.

currentPlaybackTime
Link copied to clipboard
val currentPlaybackTime: Float

Get the playback time of the current song or 0.

currentPlayDuration
Link copied to clipboard
val currentPlayDuration: Float

Total length of the song or 0.

localOfflineStationList
Link copied to clipboard
val localOfflineStationList: StationList

Return a list of all offline stations that have music stored locally and are ready for playback

maxBitrate
Link copied to clipboard
var maxBitrate: Int

The desired bitrate (in terms of kb/s) of songs retrieved from the Adaptr servers. A value of 0 means request the highest available bitrate.

mixingAudioPlayerEventListener
Link copied to clipboard
mSessionUpdateListener
Link copied to clipboard
var mSessionUpdateListener: SessionUpdateListener? = null
notificationStyle
Link copied to clipboard
var notificationStyle: NotificationStyle?

The current NotificationStyle in use by Adaptr.

offlineStorageUsed
Link copied to clipboard
val offlineStorageUsed: Long

Return the number of bytes used for audio files stored on the local device for offline playback.

pendingIntent
Link copied to clipboard
var pendingIntent: PendingIntent? = null

This PendingIntent is attached to any Notification created by Adaptr.

playHistory
Link copied to clipboard
val playHistory: MutableList<Play>

History of items played since the app started

remoteOfflineStationList
Link copied to clipboard
var remoteOfflineStationList: StationList

Return a list of all stations that may be downloaded to the local device for playback. None of these stations can be passed to setActiveStation() - they may only be passed to downloadAndSync() to create a matching local offline station that can be played back.

secondsOfCrossfade
Link copied to clipboard
var secondsOfCrossfade: Float

Duration of song cross fades. This value Will be ignored if crossfade values are assigned by the server.

state
Link copied to clipboard
var state: State

The current state of the FeedAudioPlayer.

stationList
Link copied to clipboard
val stationList: StationList

Get the station list currently available for streaming. See also getLocalOfflineStationList() and getRemoteOfflineStationList().