Skip to content

Commit

Permalink
repeat mode added
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrafzadeh committed Aug 20, 2018
1 parent 476aab3 commit 6ca4acb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class AudioStreamingManager extends StreamingManager {
private MediaMetaData currentAudio;
private List<MediaMetaData> mediaList = new ArrayList<>();
public static volatile Handler applicationHandler = null;
private boolean repeatEnable = false;
private boolean shuffleEnable = false;


public static AudioStreamingManager getInstance(Context context) {
Expand Down Expand Up @@ -68,6 +70,22 @@ public String getCurrentAudioId() {
return currentAudio != null ? currentAudio.getMediaId() : "";
}

public void setRepeatEnable(boolean repeatEnable) {
this.repeatEnable = repeatEnable;
}

public boolean isRepeatEnable() {
return repeatEnable;
}

public void setShuffleEnable(boolean shuffleEnable) {
this.shuffleEnable = shuffleEnable;
}

public boolean isShuffleEnable() {
return shuffleEnable;
}

public boolean isPlayMultiple() {
return playMultiple;
}
Expand Down Expand Up @@ -148,6 +166,11 @@ public int lastSeekPosition() {
@Override
public void onSkipToNext() {
int nextIndex = index + 1;
if (!isValidIndex(true, nextIndex))
if (repeatEnable)
nextIndex = 0;
else return;

if (isValidIndex(true, nextIndex)) {
MediaMetaData metaData = mediaList.get(nextIndex);
onPlay(metaData);
Expand All @@ -161,6 +184,12 @@ public void onSkipToNext() {
@Override
public void onSkipToPrevious() {
int prvIndex = index - 1;

if (!isValidIndex(true, prvIndex))
if (repeatEnable)
prvIndex = mediaList.size() - 1;
else return;

if (isValidIndex(false, prvIndex)) {
MediaMetaData metaData = mediaList.get(prvIndex);
onPlay(metaData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package dm.audiostreamer;

import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
Expand All @@ -18,6 +17,7 @@
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
Expand All @@ -26,10 +26,13 @@
import android.widget.RemoteViews;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.NotificationTarget;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.bumptech.glide.request.target.Target;


public class AudioStreamingService extends Service implements NotificationManager.NotificationCenterDelegate {
Expand Down Expand Up @@ -147,7 +150,7 @@ public void run() {
}
return START_NOT_STICKY;
}

Bitmap albumArt = null;
private void createNotification(MediaMetaData mSongDetail) {
try {
String songName = mSongDetail.getMediaTitle();
Expand Down Expand Up @@ -181,7 +184,7 @@ private void createNotification(MediaMetaData mSongDetail) {
setListeners(expandedView);
}

Bitmap albumArt = null;

// try {
// ImageLoader imageLoader = ImageLoader.getInstance();
// albumArt = imageLoader.loadImageSync(audioInfo.getMediaArt());
Expand Down Expand Up @@ -232,6 +235,18 @@ private void createNotification(MediaMetaData mSongDetail) {
.applyDefaultRequestOptions(options)
.asBitmap()
.load(audioInfo.getMediaArt())
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
albumArt = resource;
return false;
}
})
.into(notificationTarget);


Expand Down

0 comments on commit 6ca4acb

Please sign in to comment.