Search in sources :

Example 6 with Media

use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.

the class MediaIdPlaybackInitializerImpl method playFromMediaId.

@Override
public void playFromMediaId(final long mediaId) {
    int position = -1;
    List<Media> queue = playbackData.getQueue();
    if (queue != null && !queue.isEmpty()) {
        int loopPos = 0;
        for (final Media item : queue) {
            if (item.getId() == mediaId) {
                position = loopPos;
                break;
            }
            loopPos++;
        }
    }
    if (queue != null && position != -1) {
        play(queue, position);
    } else {
        playFromQueueSource(mediaProvider.load(mediaId));
    }
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media)

Example 7 with Media

use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.

the class QueueProviderFilesMediaStore method mediaFromFile.

@NonNull
private static Media mediaFromFile(@NonNull final Uri uri) {
    final MediaMetadataRetriever r = new MediaMetadataRetriever();
    try {
        r.setDataSource(uri.getPath());
        final Media media = new Media();
        media.setTitle(r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));
        media.setArtist(r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
        media.setAlbum(r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
        media.setData(uri);
        final String duration = r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        if (!TextUtils.isEmpty(duration)) {
            try {
                media.setDuration(Long.parseLong(duration));
            } catch (NumberFormatException e) {
                Log.w(TAG, "mediaFromFile() duration is not a number: " + duration);
            }
        }
        final String trackNumber = r.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
        if (!TextUtils.isEmpty(trackNumber)) {
            try {
                media.setTrack(Integer.parseInt(duration));
            } catch (NumberFormatException e) {
                Log.w(TAG, "mediaFromFile() track number is not a number: " + duration);
            }
        }
        return media;
    } finally {
        r.release();
    }
}
Also used : MediaMetadataRetriever(android.media.MediaMetadataRetriever) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) NonNull(android.support.annotation.NonNull)

Example 8 with Media

use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.

the class QueueProviderTracksMediaStore method queueFromTracksSearch.

@NonNull
@WorkerThread
private List<Media> queueFromTracksSearch(@Nullable final String query) {
    final List<Long> ids = new ArrayList<>(15);
    final StringBuilder sel = new StringBuilder(256);
    sel.append(MediaStoreTracksProvider.SELECTION_NON_HIDDEN_MUSIC);
    if (!TextUtils.isEmpty(query)) {
        final String likeQuery = " LIKE " + SqlUtils.escapeAndWrapForLikeArgument(query);
        sel.append(" AND (").append(MediaStore.Audio.Media.TITLE).append(likeQuery);
        sel.append(" OR ").append(MediaStore.Audio.Media.ARTIST).append(likeQuery);
        sel.append(" OR ").append(MediaStore.Audio.Media.ALBUM).append(likeQuery);
        sel.append(')');
    }
    final List<Media> fromProvider = mMediaProvider.load(sel.toString(), null, MediaStore.Audio.Media.ALBUM + ',' + MediaStore.Audio.Media.TRACK, QueueConfig.MAX_QUEUE_SIZE).take(1).blockingFirst();
    for (final Media media : fromProvider) {
        ids.add(media.getId());
    }
    if (!TextUtils.isEmpty(query) && fromProvider.size() < QueueConfig.MAX_QUEUE_SIZE) {
        // Search in genres for tracks with media ids that do not match found ids
        Cursor c = mContentResolver.query(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, MediaStore.Audio.Genres.NAME + "=?", new String[] { StringUtils.capWords(query) }, null);
        Long genreId = null;
        if (c != null) {
            try {
                if (c.moveToFirst()) {
                    genreId = c.getLong(0);
                }
            } finally {
                c.close();
            }
        }
        if (genreId != null) {
            fromProvider.addAll(mMediaProvider.load(MediaStore.Audio.Genres.Members.getContentUri(MediaStoreVolumeNames.EXTERNAL, genreId), SelectionUtils.notInSelection(MediaStore.Audio.Media._ID, ids), null, "RANDOM()", QueueConfig.MAX_QUEUE_SIZE - ids.size()).take(1).blockingFirst());
        }
    }
    return fromProvider;
}
Also used : ArrayList(java.util.ArrayList) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 9 with Media

use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.

the class QueueRecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final QueueItemViewHolder viewHolder, final int position) {
    final Media item = getItem(position);
    viewHolder.textTitle.setText(item.getTitle());
    viewHolder.textArtist.setText(item.getArtist());
    BindingAdapters.setFormattedDuration(viewHolder.textDuration, item.getDuration() / 1000L);
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media)

Example 10 with Media

use of com.doctoror.fuckoffmusicplayer.domain.queue.Media in project PainlessMusicPlayer by Doctoror.

the class QueueRecyclerAdapter method onMenuClick.

private void onMenuClick(@NonNull final View itemView, final int position) {
    final PopupMenu popup = new PopupMenu(itemView.getContext(), itemView);
    final Menu popupMenu = popup.getMenu();
    final MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.list_item_media, popupMenu);
    final Media item = getItem(position);
    popup.setOnMenuItemClickListener(menuItem -> onMenuItemClick(menuItem, item));
    popup.show();
}
Also used : MenuInflater(android.view.MenuInflater) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(android.widget.PopupMenu)

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