/ArgPlayer

An android music player library

Primary LanguageJavaApache License 2.0Apache-2.0

ArgPlayer

An android music player ui library

Builds:

Table of Contents

Installation

To always build from the latest commit with all updates. Add the JitPack repository:

(path:\to\your\projects\MainFolderOfYourProject\build.gradle)


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

Set minSdkVersion to 21 and add the following dependency:

android{
  ...
  defaultConfig{
    ...
    minSdkVersion 21
    ...
  }
}
dependencies {
    implementation 'com.github.mergehez:ArgPlayer:v3.1'
}

Note: You may encounter the error below. See this stackoverflow question: link
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'

How to use

XML Codes

for small view:

<com.arges.sepan.argmusicplayer.PlayerViews.ArgPlayerSmallView
	android:id="@+id/argmusicplayer"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"/>

for large view:

<com.arges.sepan.argmusicplayer.PlayerViews.ArgPlayerLargeView
	android:id="@+id/argmusicplayer"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"/>

for full screen view:

<com.arges.sepan.argmusicplayer.PlayerViews.ArgPlayerFullScreenView
	android:id="@+id/argmusicplayer"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"/>

Simplest Usage

Play Simple Audio

@Override
protected void onCreate(Bundle savedInstanceState) {
	//... other codes ...
	String url = "https://www.gotinenstranan.com/songs/joan-baez-north-country-blues.mp3";
	ArgAudio audio = ArgAudio.createFromURL("Joan Baez", "North Country Blues", url);

	ArgPlayerSmallView argMusicPlayer = (ArgPlayerSmallView) findViewById(R.id.argmusicplayer);
	argMusicPlayer.play(audio);
	//... other codes ...
}

Play Playlist

@Override
protected void onCreate(Bundle savedInstanceState) {
	//... other codes ...
	ArgAudio audio1 = ArgAudio.createFromURL("Joan Baez", "North Country Blues", url1)
	//Define audio2, audio3, audio4 ......
	ArgAudioList playlist = new ArgAudioList(true).add(audio1)
						.add(audio2)
						.add(audio3)
						.add(audio4);

	ArgPlayerSmallView argMusicPlayer = (ArgPlayerSmallView) findViewById(R.id.argmusicplayer);
	argMusicPlayer.playPlaylist(playlist );
	//... other codes ...
}

Player Methods

Return Method/Description
void play(ArgAudio audio)
Directly plays an audio
void playPlaylist(ArgAudioList list)
Directly plays a playlist
void loadSingleAudio(ArgAudio audio)
Loads an audio to play later
void playLoadedSingleAudio()
Plays the loaded audio if exists
void loadPlaylist(ArgAudioList list)
Loads a playlist to play later
void playLoadedPlaylist()
Plays the loaded playlist if exists
void pause()
Pauses a playing audio
void resume()
Resumes the playing audio
void stop()
Stops audio
boolean seekTo(int millisec)
Seeks audio to milliSec
return: if seeking position is greater than duration or less than 0, it returns false
boolean forward(int milliSec, boolean willPlay)
Forward audio as long as milliSec
willPlay: if audio will play after forwarding, set this true
return: If forwarding position is greater than duration, it returns false
boolean backward(int milliSec, boolean willPlay)
Backward audio as long as milliSec
willPlay: if audio will play after backwarding, set this true
return: If backwarding position is less than 0, it returns false
ArgAudio getCurrentAudio()
Gets the current audio if available
long getDuration()
Gets duration of current audio
boolean isPlaying()
Checks if an audio is playing
boolean isPaused()
Checks if an audio is paused
void playAudioAfterPercent(int percent)
Audio plays as soon as %percent is buffered. Only when audio type is Url. Default percent is %50.
void enableProgress() and disableProgress()
Enable/Disable Progress View. As default is enabled
void setProgressMessage(String message)
Change Progress View message. Default message is 'Audio is Loading..'
void enableErrorView() and disableErrorView()
Enables/Disables Error View. Error view appears when an error occurs. Default value is enabled
void enableNextPrevButtons()and disableNextPrevButtons()
Enables/disables next/previous playback control. Default behavior is enabled
void enableNotification(Activity activity)
Enables notification. Look at screenshots..
activity: Current activity (You'd probably pass this keyword).
void enableNotification(ArgNotificationOptions options)
Enables notification with custom options such as image, channel name etc.
options: An ArgNotificationOptions instance.
void disableNotification()
Disable notification option. If notification was enabled before, it will be cancelled. Default value for Notification is disabled
void continuePlaylistWhenError()
If an error occures, player won't publish error and will play next audio.
void stopPlaylistWhenError()
If an error occures, player will stop playing and publish error. As default player publishes errors.
void setPlaylistRepeat(boolean repeat)
Sets repetition of the playlist. Default value is true
void setAllButtonsImageResource(int resIdPlay,int resIdPause,int resIdPrev,int resIdNext,int resIdRepeat,int resIdNotRepeat)
You can change image resources of all control buttons by this method.
void setPrevButtonImageResource(int resId)
Sets image resource of the previous control button
void setNextButtonImageResource(int resId)
Changes image resource of the next control button
void setPlayButtonImageResource(int resId)
Sets image resource of the play control button
void setPauseButtonImageResource(int resId)
Sets image resource of the pause control button
void setRepeatButtonImageResource(int repeatResId, int notRepeatResId)
Sets image resource of the repeat control button.
repeatResId: when repetition is enabled
notRepeatResId: when repetition is disabled
void setOnErrorListener(Arg.OnErrorListener onErrorListener)
setOnPreparedListener(Arg.OnPreparedListener onPreparedListener)
setOnPausedListener(Arg.OnPausedListener onPausedListener)
setOnPlayingListener(Arg.OnPlayingListener onPlayingListener)
setOnCompletedListener(Arg.OnCompletedListener onCompletedListener)
setOnTimeChangeListener(Arg.OnTimeChangeListener onTimeChangeListener)
setOnPlaylistAudioChangedListener(Arg.OnPlaylistAudioChangedListener onPlaylistAudioChangedListener)
Sets listeners to handle broadcasts

ArgAudio

Return Method/Description
ArgAudio staticcreateFromRaw(@RawRes int rawId)
Short way to create an audio from raw resources. Singer and audio name will be set to rawId.
ArgAudio staticcreateFromRaw(String singer, String audioName, @RawRes int rawId)
Creates a raw type audio.
ArgAudio staticcreateFromAssets(String assetName)
Short way to create an audio from raw resources. Singer and audio name will be set to assetName.
ArgAudio staticcreateFromAssets(String singer, String audioName, String assetName)
Creates an assets type audio.
ArgAudio staticcreateFromURL(String url)
Short way to create an audio from raw resources. Singer and audio name will be set to url.
ArgAudio staticcreateFromURL(String singer, String audioName, String url)
Creates an url type audio.
ArgAudio staticcreateFromFilePath(String filePath)
Creates a filepath type audio.
ArgAudio staticcreateFromFilePath(String singer, String audioName, String filePath)
Short way to create an audio from raw resources. Singer and audio name will be set to filePath.
ArgAudio cloneAudio()
Clones the audio.
ArgAudio convertToPlaylist()
Makes audio as a playlist audio.
boolean isPlaylist()
Checks if the audio is a playlist audio.

ArgAudioList

Return Method/Description
ArgAudioList add(@NonNull ArgAudio audio)
Add an ArgAudio
ArgAudio getCurrentAudio()
Gets current(playing) audio.
int getCurrentIndex()
Gets index of current audio.
boolean equals(Object obj)
Checks if another ArgAudioList object is equal to the current one. Checks emptyness, equalness of first and last childs of objects and sizes.
void goTo(int index)
Changes playing audio of playlist.
boolean hasNext()
Checks if any next audio
int getNextIndex()
Gets index of next audio.
boolean goToNext()
Sets next audio as playing audio. If this action is not possible, method returns false.
boolean hasPrev()
Checks if any previous audio
int getPrevIndex()
Gets index of previous audio.
boolean goToPrev()
Sets previous audio as playing audio. If this action is not possible, method returns false.

ArgNotificationOptions

Return Method/Description
OnBuildNotificationListener getListener()
Gets the listener.
ArgNotificationOptions setListener()
Sets the listener.
bool isProgressEnabled()
Checks whether progress is enabled.
ArgNotificationOptions setProgressEnabled(boolean progressEnabled)
Checks whether progress is enabled. (Current time and a progress view is visible if set to true)
int getNotificationId()
Gets notification id.
ArgNotificationOptions setNotificationId(int notificationId)
Sets notification id.
String getChannelId()
Gets channel id.
Requires MinSDK of 26 (O)
ArgNotificationOptions setChannelId(CharSequence channelId)
Sets channel id.
Requires MinSDK of 26 (O)
String getChannelName()
Gets channel name.
Requires MinSDK of 26 (O)
ArgNotificationOptions setChannelName(CharSequence channelName)
Sets channel name.
Requires MinSDK of 26 (O)

ScreenShots

Progress View

Error View

Notification

Small Player View

Large Player View

Fullscreen Player View