mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
The last element listened to is the first in the list at the next start
This commit is contained in:
parent
9328ec87ab
commit
15e7c28b14
4 changed files with 59 additions and 3 deletions
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.service;
|
|||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
|
|
@ -44,6 +45,7 @@ public class MediaManager {
|
|||
if (mediaBrowserListenableFuture.isDone()) {
|
||||
mediaBrowserListenableFuture.get().clearMediaItems();
|
||||
mediaBrowserListenableFuture.get().setMediaItems(MappingUtil.mapMediaItems(context, songs));
|
||||
mediaBrowserListenableFuture.get().seekTo(getQueueRepository().getLastPlayedSongIndex(), 0);
|
||||
mediaBrowserListenableFuture.get().prepare();
|
||||
}
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
|
|
@ -238,6 +240,10 @@ public class MediaManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static void timestamp(MediaItem mediaItem) {
|
||||
if (mediaItem != null) getQueueRepository().setTimestamp(mediaItem.mediaId);
|
||||
}
|
||||
|
||||
private static QueueRepository getQueueRepository() {
|
||||
return new QueueRepository(App.getInstance());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.media3.common.AudioAttributes;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.session.MediaLibraryService;
|
||||
import androidx.media3.session.MediaSession;
|
||||
|
|
@ -26,6 +27,7 @@ public class MediaService extends MediaLibraryService {
|
|||
public void onCreate() {
|
||||
super.onCreate();
|
||||
initializePlayer();
|
||||
initializePlayerListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -73,4 +75,14 @@ public class MediaService extends MediaLibraryService {
|
|||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private void initializePlayerListener() {
|
||||
player.addListener(new Player.Listener() {
|
||||
@Override
|
||||
public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
|
||||
MediaManager.timestamp(mediaItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue