urban-health-labs / Goonj

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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Goonj

Simple music streaming android library

Goonj integrate to your project in under a minute

Step 1:

Add following in build.gradle (Project level):

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

Step 2:

Add following in build.gradle (App level):

dependencies {
    implementation 'com.github.rever-ai:goonj:0.5.8'
    // Exo Player
    implementation 'com.google.android.exoplayer:exoplayer-core:2.10.3'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.3'
    implementation 'com.google.android.exoplayer:extension-mediasession:2.10.0'
    // Rx
    implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'


}

Usage

Register Goonj

To register Goonj, add following line:

Goonj.register<AudioPlayerActivity>(context)

where AudioPlayerActivity is activity that will open on clicking Notification.

Unregister Goonj

To unregister Goonj, add following line:

Goonj.unregister()

To use player actions, implement GoonjPlayer interface or use Goonj singleton instance

GoonjPlayer Interface could be implemented in following way

class AudioPlayerActivity : AppCompatActivity(), GoonjPlayer

    ....
    someMethod()
    val property = someProperty
    ....

Goonj Singleton could be used in following way

Goonj.someMethod() or Goonj.someProperty

Goonj(Singleton) or GoonjPlayer(Interface)

Method/Property Description
startNewSession() Starts a new Audio Session. Clears existing playlist.
resume() Resume the player.
pause() Pauses the player.
finishTrack() Manual finish track.
seekTo(positionMs: Long) Seek by a certain position, could be used with trackPosition to move forward or backward.
addTrack(track : Track, index: Int? = null) Add an audio to playlist.
removeTrack(index : Int) Removes track from current Index in the playlist.
moveTrack(currentIndex : Int, finalIndex : Int) Moves a particular track from one place in the playlist to another.
skipToNext() Skip to next track.
skipToPrevious() Skip to previous track.
customiseNotification(useNavigationAction: Boolean, usePlayPauseAction: Boolean, fastForwardIncrementMs: Long, rewindIncrementMs: Long, smallIcon: Int) Customise notification which appear while playing.
changeActivityIntentForNotification(intent: Intent) Set activity on notification click.
removeNotification() Remove notification.
register(context: Context) Simplest way to register Goonj.
register(context: Context, activityIntent: Intent) Extras with intent could be sent.
register<S: GoonjService>(context: Context, activityIntent: Intent, audioServiceClass: Class) Advanced registration for custom AudioService implementation.
unregister() unregister Goonj
imageLoader Track image loader, used to load image in notification (((Track, (Bitmap?) -> Unit) -> Unit))
tryPreFetchAtProgress Try pre-fetching at track progress
trackPreFetcher Track pre-fetcher, which could be used to load further tracks
preFetchDistanceWithAutoplay Try pre-fetching when this much track left to play, while on autoplay
preFetchDistanceWithoutAutoplay Try pre-fetching when this much track left to play, while not on autoplay
autoplay Enable autoplay with auto-fetch tracks, could be used get current state of autoplay.
trackList Get current playlist.
playerState Get player state (GoonjPlayerState).
currentTrack Get current track (Track).
lastCompletedTrack Get last completed track (Track).
trackPosition Get current track position in milli-seconds (Long).
trackProgress Get current track progress between 0 to 1 (Double).
playerStateFlowable Flowable of (GoonjPlayerState) that tells if the Player state. Helps in updating Play/Pause Icon/Button in UI.
currentTrackFlowable Flowable of (Track) that contains details of the Current Track that is playing.
autoplayFlowable Flowable of (Track) that contains details of the Current Track that is playing.
downloadStateFlowable Flowable of (DownloadState).
isDownloaded(trackId: String) Check if given track is downloaded.
trackCompletionObservable Observable of (Track) that get completed after subscription.
iconWhileDownload Drawable int used as icon while download active in notification.
maxCacheBytes Max cache size in bytes.

Cast

Feature under development

About

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:MIT License


Languages

Language:Kotlin 99.6%Language:Java 0.4%