Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.rever-ai:goonj:v0.2.1'
}
In your onCreate(), add the following lines:
PlaybackManager.getInstance(this).register(pendingIntent)
where pendingIntent is the Intent which defines what is activity that on click on Notification will take to. Example:
pendingIntent = Intent(applicationContext, AudioPlayerActivity::class.java)
In your onDestroy(), add the following lines:
PlaybackManager.getInstance(this).unregister()
To use Audio player actions, implement GoonjPlayer interface in your Activity/Fragment.
class AudioPlayerActivity : AppCompatActivity(), GoonjPlayer
Method | Description |
---|---|
startNewSession(context:Context) | Starts a new Audio Session. Clears existing playlist. |
addAudioToPlaylist(context: Context, audioTrack: Samples.Track, index: Int ?= -1) | Add an audio to playlist. |
play(context: Context) | Resume the player |
pause(context: Context) | Pauses the player |
seek(context: Context, positionMs: Long?) | Seek by a certain length. +ve values seek forward, -ve seek backward. |
setAutoplay(context: Context, autoplay : Boolean, indexFromLast: Int, autoLoadListener: AutoLoadListener) | Lets you enable Autoplay with auto-fetch tracks. |
session(context: Context) : List<Samples.Track> | Returns current playlist |
removeTrack(context: Context,index : Int) | Removes track from current Index in the playlist |
moveTrack(context: Context, currentIndex : Int, finalIndex : Int) | Moves a prticular track from one place in the playlist to another. |
skipToNext(context: Context) | Skip to next track. |
skipToPrevious(context: Context) | Skip to previous track |
isPlayingLiveData(context: Context) | Returns a LiveData that tells if the Player is paused or playing. Helps in updating Play/Pause Icon/Button in UI. |
currentPlayingTrack(context: Context) | Returns a LiveData that contains details of the Current Track that is playing. |
analyticsObservable : Observable | Add an Observer onto this to capture Analytics from the Player events. |
To support ChromeCast, add CastButtonFactory.setUpMediaRouteButton(this, yourMediaRouterButtonInXML)
to your Activity/Fragment and add yourMediaRouterButtonInXML
in your XML Layout.
** Note **: Cast doesn't supports Autoplay.