Skip to content

Commit

Permalink
Pass media browser error as ErrorInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
haggaie committed Aug 1, 2023
1 parent 156f297 commit 515f0bd
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.schabi.newpipe.database.history.model.StreamHistoryEntry;
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
import org.schabi.newpipe.error.ErrorInfo;
import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
import org.schabi.newpipe.player.PlayerService;
import org.schabi.newpipe.player.playqueue.PlayQueue;
Expand Down Expand Up @@ -219,10 +222,14 @@ private void playbackError(@StringRes final int resId, final int code) {
sessionConnector.setCustomErrorMessage(playerService.getString(resId), code);
}

private void playbackError(@NonNull final ErrorInfo errorInfo) {
playbackError(errorInfo.getMessageStringId(), PlaybackStateCompat.ERROR_CODE_APP_ERROR);
}

private Single<PlayQueue> extractPlayQueueFromMediaId(final String mediaId) {
final Uri mediaIdUri = Uri.parse(mediaId);
if (mediaIdUri == null) {
return Single.error(new NullPointerException());
return Single.error(new ContentNotAvailableException("Media ID cannot be parsed"));
}
if (mediaId.startsWith(ID_BOOKMARKS)) {
final var path = mediaIdUri.getPathSegments();
Expand Down Expand Up @@ -256,7 +263,7 @@ private Single<PlayQueue> extractPlayQueueFromMediaId(final String mediaId) {
}
}

return Single.error(new NullPointerException());
return Single.error(new ContentNotAvailableException("Media ID cannot be parsed"));
}

@Override
Expand Down Expand Up @@ -294,8 +301,8 @@ public void onPrepareFromMediaId(@NonNull final String mediaId, final boolean pl
NavigationHelper.playOnBackgroundPlayer(playerService, playQueue,
playWhenReady);
},
throwable -> playbackError(R.string.error_http_not_found,
PlaybackStateCompat.ERROR_CODE_NOT_SUPPORTED)
throwable -> playbackError(new ErrorInfo(throwable, UserAction.PLAY_STREAM,
"Failed playback of media ID [" + mediaId + "]: "))
);
}

Expand Down

0 comments on commit 515f0bd

Please sign in to comment.