Skip to content

A music player library that supports stream playback with download feature, remote playback, and analytics. It is build on Exo-Player and Google Cast framework.

License

Notifications You must be signed in to change notification settings

urban-health-labs/Goonj

Repository files navigation

Goonj

An all purpose music player library

How to add Goonj to your Android application

Step 1:

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
} 

Step 2:

Add the dependency

dependencies {
	implementation 'com.github.rever-ai:goonj:v0.2.1'
}

Usage

Register Service

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)

Unregister Service

In your onDestroy(), add the following lines:

PlaybackManager.getInstance(this).unregister()

Implement GoonjPlayer Interface

To use Audio player actions, implement GoonjPlayer interface in your Activity/Fragment.

class AudioPlayerActivity : AppCompatActivity(), GoonjPlayer

Methods

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.

Cast

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.