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