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));
}
}
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();
}
}
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;
}
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);
}
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();
}
Aggregations