Load full stream info when enqueuing a stream

This commit calls getStreamInfo causing a full network fetch of stream
info (I believe only if required) when adding a stream item to the
queue. This should prevent UI issues of missing metadata when queueing
videos that have been fast-loaded and are missing metadata.

Fixes #7035
This commit is contained in:
Douile 2021-09-01 00:55:56 +01:00
parent 8272b2508b
commit 62d36126ea
No known key found for this signature in database
GPG Key ID: DAB413485BA6CFFD
1 changed files with 35 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package org.schabi.newpipe.util;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
@ -20,6 +21,7 @@ import java.util.Collections;
import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
@ -60,11 +62,15 @@ public enum StreamDialogEntry {
* Info: Add this entry within showStreamDialog.
*/
enqueue(R.string.enqueue_stream, (fragment, item) -> {
NavigationHelper.enqueueOnPlayer(fragment.getContext(), new SinglePlayQueue(item));
fetchItemInfoIfSparse(item,
fullItem -> NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem)
);
}),
enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> {
NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), new SinglePlayQueue(item));
fetchItemInfoIfSparse(item,
fullItem -> NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem)
);
}),
start_here_on_background(R.string.start_here_on_background, (fragment, item) ->
@ -203,4 +209,31 @@ public enum StreamDialogEntry {
fragment.requireActivity().getSupportFragmentManager(),
item.getServiceId(), uploaderUrl, item.getUploaderName());
}
/////////////////////////////////////////////
// helper functions //
/////////////////////////////////////////////
private interface InfoCallback {
void onInfo(SinglePlayQueue item);
}
private static void fetchItemInfoIfSparse(final StreamInfoItem item,
final InfoCallback callback) {
if (item.getDuration() < 0) {
// Sparse item: fetched by fast fetch
final Disposable currentWorker = ExtractorHelper.getStreamInfo(
item.getServiceId(),
item.getUrl(),
false
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
callback.onInfo(new SinglePlayQueue(result));
}, throwable -> Log.e("StreamDialogEntry", throwable.toString()));
} else {
callback.onInfo(new SinglePlayQueue(item));
}
}
}