@@ -13,7 +13,6 @@ import androidx.media.MediaBrowserServiceCompat.Result
1313import androidx.media.utils.MediaConstants
1414import io.reactivex.rxjava3.core.Flowable
1515import io.reactivex.rxjava3.core.Single
16- import io.reactivex.rxjava3.core.SingleSource
1716import io.reactivex.rxjava3.disposables.CompositeDisposable
1817import io.reactivex.rxjava3.schedulers.Schedulers
1918import org.schabi.newpipe.MainActivity.DEBUG
@@ -25,10 +24,8 @@ import org.schabi.newpipe.database.playlist.PlaylistStreamEntry
2524import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity
2625import org.schabi.newpipe.extractor.InfoItem
2726import org.schabi.newpipe.extractor.InfoItem.InfoType
28- import org.schabi.newpipe.extractor.ListInfo
2927import org.schabi.newpipe.extractor.channel.ChannelInfoItem
3028import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
31- import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException
3229import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
3330import org.schabi.newpipe.extractor.search.SearchInfo
3431import org.schabi.newpipe.extractor.stream.StreamInfoItem
@@ -86,6 +83,10 @@ class MediaBrowserImpl(
8683
8784 // region onLoadChildren
8885 fun onLoadChildren (parentId : String , result : Result <List <MediaBrowserCompat .MediaItem >>) {
86+ if (DEBUG ) {
87+ Log .d(TAG , " onLoadChildren($parentId )" )
88+ }
89+
8990 result.detach() // allows sendResult() to happen later
9091 disposables.add(
9192 onLoadChildren(parentId)
@@ -101,10 +102,6 @@ class MediaBrowserImpl(
101102 }
102103
103104 private fun onLoadChildren (parentId : String ): Single <List <MediaBrowserCompat .MediaItem >> {
104- if (DEBUG ) {
105- Log .d(TAG , " onLoadChildren($parentId )" )
106- }
107-
108105 try {
109106 val parentIdUri = Uri .parse(parentId)
110107 val path = ArrayList (parentIdUri.pathSegments)
@@ -353,15 +350,12 @@ class MediaBrowserImpl(
353350 private fun populateRemotePlaylist (playlistId : Long ): Single <List <MediaBrowserCompat .MediaItem >> {
354351 return RemotePlaylistManager (database).getPlaylist(playlistId).firstOrError()
355352 .flatMap { ExtractorHelper .getPlaylistInfo(it.serviceId, it.url, false ) }
356- .flatMap { info ->
357- info.errors.firstOrNull { it !is ContentNotSupportedException }?.let {
358- return @flatMap Single .error(it)
353+ .map {
354+ // ignore it.errors, i.e. ignore errors about specific items, since there would
355+ // be no way to show the error properly in Android Auto anyway
356+ it.relatedItems.mapIndexed { index, item ->
357+ createRemotePlaylistStreamMediaItem(playlistId, item, index)
359358 }
360- Single .just(
361- info.relatedItems.mapIndexed { index, item ->
362- createRemotePlaylistStreamMediaItem(playlistId, item, index)
363- }
364- )
365359 }
366360 }
367361 // endregion
@@ -371,10 +365,16 @@ class MediaBrowserImpl(
371365 query : String ,
372366 result : Result <List <MediaBrowserCompat .MediaItem >>
373367 ) {
368+ if (DEBUG ) {
369+ Log .d(TAG , " onSearch($query )" )
370+ }
371+
374372 result.detach() // allows sendResult() to happen later
375373 disposables.add(
376374 searchMusicBySongTitle(query)
377- .flatMap { this .mediaItemsFromInfoItemList(it) }
375+ // ignore it.errors, i.e. ignore errors about specific items, since there would
376+ // be no way to show the error properly in Android Auto anyway
377+ .map { it.relatedItems.mapNotNull(this ::createInfoItemMediaItem) }
378378 .subscribeOn(Schedulers .io())
379379 .subscribe(
380380 { result.sendResult(it) },
@@ -391,20 +391,6 @@ class MediaBrowserImpl(
391391 val serviceId = ServiceHelper .getSelectedServiceId(context)
392392 return ExtractorHelper .searchFor(serviceId, query, listOf (), " " )
393393 }
394-
395- private fun mediaItemsFromInfoItemList (
396- result : ListInfo <InfoItem >
397- ): SingleSource <List <MediaBrowserCompat .MediaItem >> {
398- result.errors.firstOrNull()?.let { return @mediaItemsFromInfoItemList Single .error(it) }
399-
400- return try {
401- Single .just(
402- result.relatedItems.mapNotNull { item -> this .createInfoItemMediaItem(item) }
403- )
404- } catch (e: Exception ) {
405- Single .error(e)
406- }
407- }
408394 // endregion
409395
410396 companion object {
0 commit comments