-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Load full stream info when enqueuing a stream #7036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
62d3612
bc2f0f9
91611fc
6472e9b
3d1a360
ec7de2a
7cd3603
baee915
3ff00ff
064242d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,15 @@ | |
|
|
||
| import android.content.Context; | ||
| import android.net.Uri; | ||
| import android.util.Log; | ||
| import android.widget.Toast; | ||
|
|
||
| import androidx.fragment.app.Fragment; | ||
|
|
||
| import org.schabi.newpipe.NewPipeDatabase; | ||
| import org.schabi.newpipe.R; | ||
| import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||
| import org.schabi.newpipe.extractor.stream.StreamType; | ||
| import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; | ||
| import org.schabi.newpipe.local.dialog.PlaylistCreationDialog; | ||
| import org.schabi.newpipe.local.history.HistoryRecordManager; | ||
|
|
@@ -18,6 +20,7 @@ | |
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; | ||
| import io.reactivex.rxjava3.schedulers.Schedulers; | ||
|
|
@@ -60,20 +63,24 @@ public enum StreamDialogEntry { | |
| * Info: Add this entry within showStreamDialog. | ||
| */ | ||
| enqueue(R.string.enqueue_stream, (fragment, item) -> { | ||
| NavigationHelper.enqueueOnPlayer(fragment.getContext(), new SinglePlayQueue(item)); | ||
| fetchItemInfoIfSparse(fragment, item, fullItem -> | ||
| NavigationHelper.enqueueOnPlayer(fragment.getContext(), fullItem)); | ||
| }), | ||
|
|
||
| enqueue_next(R.string.enqueue_next_stream, (fragment, item) -> { | ||
| NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), new SinglePlayQueue(item)); | ||
| fetchItemInfoIfSparse(fragment, item, fullItem -> | ||
| NavigationHelper.enqueueNextOnPlayer(fragment.getContext(), fullItem)); | ||
| }), | ||
|
|
||
| start_here_on_background(R.string.start_here_on_background, (fragment, item) -> | ||
| NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), | ||
| new SinglePlayQueue(item), true)), | ||
| start_here_on_background(R.string.start_here_on_background, (fragment, item) -> { | ||
| fetchItemInfoIfSparse(fragment, item, fullItem -> | ||
| NavigationHelper.playOnBackgroundPlayer(fragment.getContext(), fullItem, true)); | ||
| }), | ||
|
|
||
| start_here_on_popup(R.string.start_here_on_popup, (fragment, item) -> | ||
| NavigationHelper.playOnPopupPlayer(fragment.getContext(), | ||
| new SinglePlayQueue(item), true)), | ||
| start_here_on_popup(R.string.start_here_on_popup, (fragment, item) -> { | ||
| fetchItemInfoIfSparse(fragment, item, fullItem -> | ||
| NavigationHelper.playOnPopupPlayer(fragment.getContext(), fullItem, true)); | ||
| }), | ||
|
|
||
| set_as_playlist_thumbnail(R.string.set_as_playlist_thumbnail, (fragment, item) -> { | ||
| }), // has to be set manually | ||
|
|
@@ -203,4 +210,39 @@ private static void openChannelFragment(final Fragment fragment, | |
| fragment.requireActivity().getSupportFragmentManager(), | ||
| item.getServiceId(), uploaderUrl, item.getUploaderName()); | ||
| } | ||
|
|
||
| ///////////////////////////////////////////// | ||
| // helper functions // | ||
| ///////////////////////////////////////////// | ||
|
|
||
| private static void fetchItemInfoIfSparse(final Fragment fragment, | ||
| final StreamInfoItem item, | ||
| final Consumer<SinglePlayQueue> callback) { | ||
Stypox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!(item.getStreamType() == StreamType.LIVE_STREAM | ||
| || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) | ||
| && item.getDuration() < 0) { | ||
| // Sparse item: fetched by fast fetch | ||
| ExtractorHelper.getStreamInfo( | ||
| item.getServiceId(), | ||
| item.getUrl(), | ||
| false | ||
| ) | ||
| .subscribeOn(Schedulers.io()) | ||
| .observeOn(AndroidSchedulers.mainThread()) | ||
| .subscribe(result -> { | ||
| final HistoryRecordManager recordManager = | ||
| new HistoryRecordManager(fragment.getContext()); | ||
| recordManager.saveStreamState(result, 0) | ||
| .subscribeOn(Schedulers.io()) | ||
| .observeOn(AndroidSchedulers.mainThread()) | ||
| .doOnError(throwable -> Log.e("StreamDialogEntry", | ||
| throwable.toString())) | ||
| .subscribe(); | ||
|
|
||
| callback.accept(new SinglePlayQueue(result)); | ||
| }, throwable -> Log.e("StreamDialogEntry", throwable.toString())); | ||
|
Comment on lines
+238
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should report these error via the UI. Otherwise the user gets no feedback on his action if something fails. However, I am not sure how to handle network related errors here. @Stypox Any idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we toast the user and fallback to returning the sparse info item then, although that still has its issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use an error notification, just like https://github.com/TeamNewPipe/NewPipe/pull/7538/files#diff-212f79b4111281cdfbffed5f79bca8922f99be14642ef90d524e6c9de9a436f7R66 |
||
| } else { | ||
| callback.accept(new SinglePlayQueue(item)); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the fragment used as param here? The only usage for fragment is
fragment.getContext()in this method.