Search in sources :

Example 1 with Media

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);
    }
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media)

Example 2 with Media

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;
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 3 with Media

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) WorkerThread(android.support.annotation.WorkerThread)

Example 4 with Media

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);
            }
        }
    }
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) ArrayList(java.util.ArrayList)

Example 5 with Media

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;
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) NonNull(android.support.annotation.NonNull)

Aggregations

Media (com.doctoror.fuckoffmusicplayer.domain.queue.Media)19 NonNull (android.support.annotation.NonNull)6 WorkerThread (android.support.annotation.WorkerThread)6 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Bitmap (android.graphics.Bitmap)1 MediaMetadataRetriever (android.media.MediaMetadataRetriever)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 PopupMenu (android.widget.PopupMenu)1 RemoteViews (android.widget.RemoteViews)1 PlaybackReporter (com.doctoror.fuckoffmusicplayer.domain.reporter.PlaybackReporter)1 File (java.io.File)1 LinkedHashSet (java.util.LinkedHashSet)1