mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
fix: refactor start queue to put the db writing in the background (#287)
This commit is contained in:
commit
22f196c8c0
1 changed files with 20 additions and 20 deletions
|
|
@ -1,14 +1,13 @@
|
||||||
package com.cappielloantonio.tempo.service;
|
package com.cappielloantonio.tempo.service;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.util.Log;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.OptIn;
|
import androidx.annotation.OptIn;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
|
|
@ -188,14 +187,12 @@ public class MediaManager {
|
||||||
try {
|
try {
|
||||||
if (mediaBrowserListenableFuture.isDone()) {
|
if (mediaBrowserListenableFuture.isDone()) {
|
||||||
final MediaBrowser browser = mediaBrowserListenableFuture.get();
|
final MediaBrowser browser = mediaBrowserListenableFuture.get();
|
||||||
|
|
||||||
backgroundExecutor.execute(() -> {
|
|
||||||
final List<MediaItem> items = MappingUtil.mapMediaItems(media);
|
final List<MediaItem> items = MappingUtil.mapMediaItems(media);
|
||||||
enqueueDatabase(media, true, 0);
|
|
||||||
new Handler(Looper.getMainLooper()).post(() -> {
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
justStarted.set(true);
|
justStarted.set(true);
|
||||||
browser.setMediaItems(items, startIndex, 0);
|
browser.setMediaItems(items, startIndex, 0);
|
||||||
browser.prepare();
|
browser.prepare();
|
||||||
|
|
||||||
Player.Listener timelineListener = new Player.Listener() {
|
Player.Listener timelineListener = new Player.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTimelineChanged(Timeline timeline, int reason) {
|
public void onTimelineChanged(Timeline timeline, int reason) {
|
||||||
|
|
@ -209,6 +206,9 @@ public class MediaManager {
|
||||||
};
|
};
|
||||||
browser.addListener(timelineListener);
|
browser.addListener(timelineListener);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
backgroundExecutor.execute(() -> {
|
||||||
|
enqueueDatabase(media, true, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue