use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.
the class QueueActivity method initAlbumArtAndToolbar.
private void initAlbumArtAndToolbar(@NonNull final ActivityQueueBinding binding) {
setSupportActionBar(toolbar);
ViewCompat.setTransitionName(binding.getRoot(), QueueActivity.TRANSITION_NAME_ROOT);
ViewCompat.setTransitionName(albumArt, QueueActivity.TRANSITION_NAME_ALBUM_ART);
String pic = null;
for (final Media media : queue) {
pic = media.getAlbumArt();
if (pic != null) {
break;
}
}
mCoverUri = pic;
if (TextUtils.isEmpty(pic)) {
showPlaceholderArt();
onImageSet();
} else {
loadAlbumArt(pic);
}
}
use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.
the class MediaStoreMediaProvider method loadMediaList.
@NonNull
@WorkerThread
private List<Media> loadMediaList(@NonNull final Uri contentUri, @Nullable final String selection, @Nullable final String[] selectionArgs, @Nullable final String orderBy, @Nullable final Integer limit) {
List<Media> result = null;
final StringBuilder order = new StringBuilder(128);
if (orderBy != null) {
order.append(orderBy);
}
if (limit != null) {
if (order.length() == 0) {
throw new IllegalArgumentException("Cannot use LIMIT without ORDER BY");
}
order.append(" LIMIT ").append(limit);
}
final Cursor c = mContentResolver.query(contentUri, MediaQuery.PROJECTION, selection, selectionArgs, order.length() == 0 ? null : order.toString());
if (c != null) {
result = new ArrayList<>(c.getCount());
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result.add(mediaFromCursor(c));
}
c.close();
}
return result == null ? new ArrayList<>() : result;
}
use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.
the class PlaybackDataImpl method storeToRecentAlbums.
/**
* Finds albums in queue and stores them in recently played albums.
* Album is a sequence of tracks with the same album id.
* Single playlist can be a concatination of multiple albums.
*
* @param queue The queue to process
*/
@WorkerThread
private void storeToRecentAlbums(@Nullable final List<Media> queue) {
if (queue != null && !queue.isEmpty()) {
final Set<Long> albums = new LinkedHashSet<>();
// number of items per single album
final long THRESHOLD = 4;
long prevAlbumId = -1;
int sequence = 1;
boolean first = true;
for (final Media item : queue) {
if (first) {
first = false;
prevAlbumId = item.getAlbumId();
} else {
final long albumId = item.getAlbumId();
if (albumId == prevAlbumId) {
sequence++;
} else {
if (sequence >= THRESHOLD) {
albums.add(prevAlbumId);
}
sequence = 1;
prevAlbumId = albumId;
}
}
}
if (sequence >= THRESHOLD) {
albums.add(prevAlbumId);
}
mRecentActivityManager.onAlbumsPlayed(albums);
}
}
use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.
the class PlaybackDataImpl method setPlayQueue.
@Override
public void setPlayQueue(@Nullable final List<Media> queue) {
synchronized (mQueueSubjectLock) {
final List<Media> newQueue = new ArrayList<>(queue != null ? queue.size() : 0);
if (queue != null) {
newQueue.addAll(queue);
}
final int pos = getQueuePosition();
final Media current = CollectionUtils.getItemSafe(getQueue(), pos);
mQueueSubject.onNext(newQueue);
Handlers.runOnIoThread(() -> storeToRecentAlbums(newQueue));
if (!newQueue.isEmpty() && current != null) {
final int newPos = newQueue.indexOf(current);
if (newPos != -1 && pos != newPos) {
setPlayQueuePosition(newPos);
}
}
}
}
use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.
the class PlaybackDataPersister method toProtoMediaList.
@NonNull
private static PlaybackDataProto.Media[] toProtoMediaList(@Nullable final List<Media> media) {
if (media == null || media.isEmpty()) {
return new PlaybackDataProto.Media[0];
}
final PlaybackDataProto.Media[] result = new PlaybackDataProto.Media[media.size()];
int i = 0;
for (final Media item : media) {
result[i] = toProtoMedia(item);
i++;
}
return result;
}
Aggregations