Speed up loading media info
Loading chapters can take around 5-10 seconds, depending on the media type. During that time, the player screen shows nothing or the old media file. Instead, load the chapters afterwards.
This commit is contained in:
parent
d4e1ebfa08
commit
39a990edcc
|
@ -268,7 +268,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
}
|
||||
|
||||
controller.setPlaybackSpeed(newSpeed);
|
||||
loadMediaInfo();
|
||||
loadMediaInfo(false);
|
||||
});
|
||||
butPlaybackSpeed.setOnLongClickListener(v -> {
|
||||
new VariableSpeedDialog().show(getChildFragmentManager(), null);
|
||||
|
@ -290,14 +290,16 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
txtvPlaybackSpeed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void loadMediaInfo() {
|
||||
private void loadMediaInfo(boolean includingChapters) {
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
disposable = Maybe.create(emitter -> {
|
||||
disposable = Maybe.<Playable>create(emitter -> {
|
||||
Playable media = controller.getMedia();
|
||||
if (media != null) {
|
||||
ChapterUtils.loadChapters(media, getContext());
|
||||
if (includingChapters) {
|
||||
ChapterUtils.loadChapters(media, getContext());
|
||||
}
|
||||
emitter.onSuccess(media);
|
||||
} else {
|
||||
emitter.onComplete();
|
||||
|
@ -305,9 +307,13 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> updateUi((Playable) media),
|
||||
error -> Log.e(TAG, Log.getStackTraceString(error)),
|
||||
() -> updateUi(null));
|
||||
.subscribe(media -> {
|
||||
updateUi(media);
|
||||
if (media.getChapters() == null && !includingChapters) {
|
||||
loadMediaInfo(true);
|
||||
}
|
||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)),
|
||||
() -> updateUi(null));
|
||||
}
|
||||
|
||||
private PlaybackController newPlaybackController() {
|
||||
|
@ -350,7 +356,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
|
||||
@Override
|
||||
public void onSleepTimerUpdate() {
|
||||
AudioPlayerFragment.this.loadMediaInfo();
|
||||
AudioPlayerFragment.this.loadMediaInfo(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -360,7 +366,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
|
||||
@Override
|
||||
public void loadMediaInfo() {
|
||||
AudioPlayerFragment.this.loadMediaInfo();
|
||||
AudioPlayerFragment.this.loadMediaInfo(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -397,7 +403,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
super.onStart();
|
||||
controller = newPlaybackController();
|
||||
controller.init();
|
||||
loadMediaInfo();
|
||||
loadMediaInfo(false);
|
||||
EventBus.getDefault().register(this);
|
||||
txtvRev.setText(NumberFormat.getInstance().format(UserPreferences.getRewindSecs()));
|
||||
txtvFF.setText(NumberFormat.getInstance().format(UserPreferences.getFastForwardSecs()));
|
||||
|
@ -447,7 +453,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void favoritesChanged(FavoritesEvent event) {
|
||||
AudioPlayerFragment.this.loadMediaInfo();
|
||||
AudioPlayerFragment.this.loadMediaInfo(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -124,14 +124,16 @@ public class CoverFragment extends Fragment {
|
|||
configureForOrientation(getResources().getConfiguration());
|
||||
}
|
||||
|
||||
private void loadMediaInfo() {
|
||||
private void loadMediaInfo(boolean includingChapters) {
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
disposable = Maybe.<Playable>create(emitter -> {
|
||||
Playable media = controller.getMedia();
|
||||
if (media != null) {
|
||||
ChapterUtils.loadChapters(media, getContext());
|
||||
if (includingChapters) {
|
||||
ChapterUtils.loadChapters(media, getContext());
|
||||
}
|
||||
emitter.onSuccess(media);
|
||||
} else {
|
||||
emitter.onComplete();
|
||||
|
@ -141,6 +143,9 @@ public class CoverFragment extends Fragment {
|
|||
.subscribe(media -> {
|
||||
this.media = media;
|
||||
displayMediaInfo(media);
|
||||
if (media.getChapters() == null && !includingChapters) {
|
||||
loadMediaInfo(true);
|
||||
}
|
||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||
}
|
||||
|
||||
|
@ -186,17 +191,22 @@ public class CoverFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void updateChapterControlVisibility() {
|
||||
boolean chapterControlVisible = false;
|
||||
if (media.getChapters() != null) {
|
||||
boolean chapterControlVisible = media.getChapters().size() > 0;
|
||||
int newVisibility = chapterControlVisible ? View.VISIBLE : View.GONE;
|
||||
if (chapterControl.getVisibility() != newVisibility) {
|
||||
chapterControl.setVisibility(newVisibility);
|
||||
ObjectAnimator.ofFloat(chapterControl,
|
||||
"alpha",
|
||||
chapterControlVisible ? 0 : 1,
|
||||
chapterControlVisible ? 1 : 0)
|
||||
.start();
|
||||
}
|
||||
chapterControlVisible = media.getChapters().size() > 0;
|
||||
} else if (media instanceof FeedMedia) {
|
||||
FeedMedia fm = ((FeedMedia) media);
|
||||
// If an item has chapters but they are not loaded yet, still display the button.
|
||||
chapterControlVisible = fm.getItem() != null && fm.getItem().hasChapters();
|
||||
}
|
||||
int newVisibility = chapterControlVisible ? View.VISIBLE : View.GONE;
|
||||
if (chapterControl.getVisibility() != newVisibility) {
|
||||
chapterControl.setVisibility(newVisibility);
|
||||
ObjectAnimator.ofFloat(chapterControl,
|
||||
"alpha",
|
||||
chapterControlVisible ? 0 : 1,
|
||||
chapterControlVisible ? 1 : 0)
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,11 +272,11 @@ public class CoverFragment extends Fragment {
|
|||
controller = new PlaybackController(getActivity()) {
|
||||
@Override
|
||||
public void loadMediaInfo() {
|
||||
CoverFragment.this.loadMediaInfo();
|
||||
CoverFragment.this.loadMediaInfo(false);
|
||||
}
|
||||
};
|
||||
controller.init();
|
||||
loadMediaInfo();
|
||||
loadMediaInfo(false);
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ public class ChapterSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {
|
|||
} else {
|
||||
this.dividerPos = null;
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void highlightCurrentChapter() {
|
||||
|
|
Loading…
Reference in New Issue