Skip to content

Commit c8d0983

Browse files
committed
Pass media browser error as ErrorInfo
1 parent c92f2c1 commit c8d0983

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import org.schabi.newpipe.database.history.model.StreamHistoryEntry;
2727
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
2828
import org.schabi.newpipe.database.playlist.PlaylistStreamEntry;
29+
import org.schabi.newpipe.error.ErrorInfo;
30+
import org.schabi.newpipe.error.UserAction;
31+
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
2932
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
3033
import org.schabi.newpipe.player.PlayerService;
3134
import org.schabi.newpipe.player.playqueue.PlayQueue;
@@ -219,10 +222,14 @@ private void playbackError(@StringRes final int resId, final int code) {
219222
sessionConnector.setCustomErrorMessage(playerService.getString(resId), code);
220223
}
221224

225+
private void playbackError(@NonNull ErrorInfo errorInfo) {
226+
playbackError(errorInfo.getMessageStringId(), PlaybackStateCompat.ERROR_CODE_APP_ERROR);
227+
}
228+
222229
private Single<PlayQueue> extractPlayQueueFromMediaId(final String mediaId) {
223230
final Uri mediaIdUri = Uri.parse(mediaId);
224231
if (mediaIdUri == null) {
225-
return Single.error(new NullPointerException());
232+
return Single.error(new ContentNotAvailableException("Media ID cannot be parsed"));
226233
}
227234
if (mediaId.startsWith(ID_BOOKMARKS)) {
228235
final var path = mediaIdUri.getPathSegments();
@@ -256,7 +263,7 @@ private Single<PlayQueue> extractPlayQueueFromMediaId(final String mediaId) {
256263
}
257264
}
258265

259-
return Single.error(new NullPointerException());
266+
return Single.error(new ContentNotAvailableException("Media ID cannot be parsed"));
260267
}
261268

262269
@Override
@@ -294,8 +301,8 @@ public void onPrepareFromMediaId(@NonNull final String mediaId, final boolean pl
294301
NavigationHelper.playOnBackgroundPlayer(playerService, playQueue,
295302
playWhenReady);
296303
},
297-
throwable -> playbackError(R.string.error_http_not_found,
298-
PlaybackStateCompat.ERROR_CODE_NOT_SUPPORTED)
304+
throwable -> playbackError(new ErrorInfo(throwable, UserAction.PLAY_STREAM,
305+
"Failed playback of media ID [" + mediaId + "]: "))
299306
);
300307
}
301308

0 commit comments

Comments
 (0)