Search in sources :

Example 11 with Media

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

the class MediaStoreMediaProvider method mediaFromCursor.

@NonNull
private static Media mediaFromCursor(@NonNull final Cursor c) {
    final Media media = new Media();
    media.setId(c.getLong(MediaQuery.COLUMN_ID));
    media.setTrack(c.getInt(MediaQuery.COLUMN_TRACK));
    media.setTitle(c.getString(MediaQuery.COLUMN_TITLE));
    media.setArtist(c.getString(MediaQuery.COLUMN_ARTIST));
    media.setAlbum(c.getString(MediaQuery.COLUMN_ALBUM));
    media.setAlbumId(c.getLong(MediaQuery.COLUMN_ALBUM_ID));
    media.setAlbumArt(c.getString(MediaQuery.COLUMN_ALBUM_ART));
    media.setDuration(c.getLong(MediaQuery.COLUMN_DURATION));
    final String path = c.getString(MediaQuery.COLUMN_DATA);
    if (!TextUtils.isEmpty(path)) {
        media.setData(Uri.parse(new File(path).toURI().toString()));
    }
    return media;
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) File(java.io.File) NonNull(android.support.annotation.NonNull)

Example 12 with Media

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

the class MediaSessionHolderImpl method reportMediaAndState.

@WorkerThread
private void reportMediaAndState(@NonNull final MediaSessionCompat mediaSession) {
    final PlaybackReporter playbackReporter = playbackReporterFactory.newMediaSessionReporter(mediaSession);
    final int position = playbackData.getQueuePosition();
    final Media current = CollectionUtils.getItemSafe(playbackData.getQueue(), position);
    if (current != null) {
        playbackReporter.reportTrackChanged(current, position);
    }
    playbackReporter.reportPlaybackStateChanged(playbackData.getPlaybackState(), null);
}
Also used : PlaybackReporter(com.doctoror.fuckoffmusicplayer.domain.reporter.PlaybackReporter) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) WorkerThread(android.support.annotation.WorkerThread)

Example 13 with Media

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

the class PlaybackDataPersister method toMedia.

@NonNull
private static Media toMedia(@NonNull final PlaybackDataProto.Media pm) {
    final Media media = new Media();
    media.setId(pm.id);
    media.setData(pm.data != null ? Uri.parse(pm.data) : null);
    media.setTitle(pm.title);
    media.setDuration(pm.duration);
    media.setArtist(pm.artist);
    media.setAlbumId(pm.albumId);
    media.setAlbum(pm.album);
    media.setAlbumArt(pm.albumArt);
    return media;
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) NonNull(android.support.annotation.NonNull)

Example 14 with Media

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

the class PlaybackServiceImpl method play.

private void play(@Nullable final List<Media> queue, final int position, final boolean mayContinueWhereStopped, final boolean fromPlaybackController) {
    if (queue == null) {
        throw new IllegalArgumentException("Play queue is null");
    }
    ensureFocusRequested();
    if (!mFocusGranted) {
        return;
    }
    Media media = CollectionUtils.getItemSafe(queue, position);
    if (media == null) {
        media = queue.get(0);
    }
    final Media finalMedia = media;
    if (mState == STATE_PAUSED && mCurrentTrack != null && media.getId() == mCurrentTrack.getId()) {
        mMediaPlayer.play();
        mExecutor.submit(mRunnableReportCurrentMedia);
    } else {
        mExecutor.submit(() -> {
            long seekPosition = 0;
            // If restoring from stopped state, set seek position to what it was
            if (mayContinueWhereStopped && mState == STATE_IDLE && finalMedia.equals(mCurrentMediaProvider.getCurrentMedia())) {
                seekPosition = mPlaybackData.getMediaPosition();
                if (seekPosition >= finalMedia.getDuration() - 100) {
                    seekPosition = 0;
                }
            }
            mPlaybackData.setPlayQueuePosition(position);
            mPlaybackData.setMediaPosition(seekPosition);
            mCurrentTrack = finalMedia;
            if (!fromPlaybackController) {
                getPlaybackController().setPositionInQueue(position);
            }
            reportCurrentMedia();
            reportCurrentPlaybackPosition();
            mMediaPlayer.stop();
            mMediaPlayer.load(finalMedia.getData());
            if (seekPosition != 0) {
                mMediaPlayer.seekTo(seekPosition);
            }
            mMediaPlayer.play();
        });
    }
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media)

Example 15 with Media

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

the class PlaybackServiceImpl method reportCurrentMedia.

@WorkerThread
private void reportCurrentMedia() {
    final int pos = mPlaybackData.getQueuePosition();
    final Media media = CollectionUtils.getItemSafe(mPlaybackData.getQueue(), pos);
    if (media != null) {
        mPlaybackReporter.reportTrackChanged(media, pos);
    }
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) SuppressLint(android.annotation.SuppressLint) WorkerThread(android.support.annotation.WorkerThread)

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