use of com.simplecity.amp_library.ui.screens.queue.QueueItem in project Shuttle by timusus.
the class MediaSessionManager method updateMediaSession.
private void updateMediaSession(final String action) {
int playState = playbackManager.isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
long playbackActions = getMediaSessionActions();
QueueItem currentQueueItem = queueManager.getCurrentQueueItem();
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
builder.setActions(playbackActions);
switch(queueManager.shuffleMode) {
case QueueManager.ShuffleMode.OFF:
builder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(SHUFFLE_ACTION, context.getString(R.string.btn_shuffle_on), R.drawable.ic_shuffle_off_circled).build());
break;
case QueueManager.ShuffleMode.ON:
builder.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(SHUFFLE_ACTION, context.getString(R.string.btn_shuffle_off), R.drawable.ic_shuffle_on_circled).build());
break;
}
builder.setState(playState, playbackManager.getSeekPosition(), 1.0f);
if (currentQueueItem != null) {
builder.setActiveQueueItemId((long) currentQueueItem.hashCode());
}
PlaybackStateCompat playbackState = builder.build();
if (action.equals(InternalIntents.PLAY_STATE_CHANGED) || action.equals(InternalIntents.POSITION_CHANGED) || action.equals(SHUFFLE_ACTION)) {
mediaSession.setPlaybackState(playbackState);
} else if (action.equals(InternalIntents.META_CHANGED) || action.equals(InternalIntents.QUEUE_CHANGED)) {
if (currentQueueItem != null) {
MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, String.valueOf(currentQueueItem.getSong().id)).putString(MediaMetadataCompat.METADATA_KEY_ARTIST, currentQueueItem.getSong().artistName).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, currentQueueItem.getSong().albumArtistName).putString(MediaMetadataCompat.METADATA_KEY_ALBUM, currentQueueItem.getSong().albumName).putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentQueueItem.getSong().name).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, currentQueueItem.getSong().duration).putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, (long) (queueManager.queuePosition + 1)).putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null).putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, (long) (queueManager.getCurrentPlaylist().size()));
// If we're in car mode, don't wait for the artwork to load before setting session metadata.
if (CarHelper.isCarUiMode(context)) {
mediaSession.setMetadata(metaData.build());
}
mediaSession.setPlaybackState(playbackState);
mediaSession.setQueue(QueueItemKt.toMediaSessionQueueItems(queueManager.getCurrentPlaylist()));
mediaSession.setQueueTitle(context.getString(R.string.menu_queue));
if (settingsManager.showLockscreenArtwork() || CarHelper.isCarUiMode(context)) {
updateMediaSessionArtwork(metaData);
} else {
mediaSession.setMetadata(metaData.build());
}
}
}
}
use of com.simplecity.amp_library.ui.screens.queue.QueueItem in project Shuttle by timusus.
the class MediaSessionManager method updateMediaSessionArtwork.
private void updateMediaSessionArtwork(MediaMetadataCompat.Builder metaData) {
QueueItem currentQueueItem = queueManager.getCurrentQueueItem();
if (currentQueueItem != null) {
disposables.add(Completable.defer(() -> Completable.fromAction(() -> Glide.with(context).load(currentQueueItem.getSong().getAlbum()).asBitmap().override(1024, 1024).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
if (bitmap != null) {
metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap);
}
try {
mediaSession.setMetadata(metaData.build());
} catch (NullPointerException e) {
metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null);
mediaSession.setMetadata(metaData.build());
}
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
mediaSession.setMetadata(metaData.build());
}
}))).subscribeOn(AndroidSchedulers.mainThread()).subscribe());
}
}
use of com.simplecity.amp_library.ui.screens.queue.QueueItem in project Shuttle by timusus.
the class QueueManager method makeShuffleList.
void makeShuffleList() {
if (playlist.isEmpty()) {
return;
}
shuffleList = new ArrayList<>(playlist);
QueueItem currentSong = null;
if (queuePosition >= 0 && queuePosition < shuffleList.size()) {
currentSong = shuffleList.remove(queuePosition);
}
Collections.shuffle(shuffleList);
if (currentSong != null) {
shuffleList.add(0, currentSong);
}
queuePosition = 0;
QueueItemKt.updateOccurrence(shuffleList);
}
use of com.simplecity.amp_library.ui.screens.queue.QueueItem in project Shuttle by timusus.
the class MusicService method moveToNext.
public void moveToNext(QueueItem queueItem) {
List<QueueItem> playlist = queueManager.getCurrentPlaylist();
int fromIndex = playlist.indexOf(queueItem);
QueueItem currentQueueItem = queueManager.getCurrentQueueItem();
int toIndex = playlist.indexOf(currentQueueItem) + 1;
if (fromIndex != toIndex) {
playbackManager.moveQueueItem(fromIndex, toIndex);
}
}
use of com.simplecity.amp_library.ui.screens.queue.QueueItem in project Shuttle by timusus.
the class QueueManager method removeQueueItem.
/**
* Removes the first instance of the Song the playlist & shuffleList.
*/
void removeQueueItem(QueueItem queueItem, UnsafeAction stop, UnsafeAction moveToNextTrack) {
QueueItem currentQueueItem = getCurrentQueueItem();
playlist.remove(queueItem);
shuffleList.remove(queueItem);
if (queueItem == currentQueueItem) {
onCurrentSongRemoved(stop, moveToNextTrack);
} else {
queuePosition = getCurrentPlaylist().indexOf(currentQueueItem);
}
QueueItemKt.updateOccurrence(getCurrentPlaylist());
notifyQueueChanged();
}
Aggregations