|
21 | 21 | import org.schabi.newpipe.player.playqueue.events.PlayQueueEvent; |
22 | 22 | import org.schabi.newpipe.player.playqueue.events.RemoveEvent; |
23 | 23 | import org.schabi.newpipe.player.playqueue.events.ReorderEvent; |
24 | | -import org.schabi.newpipe.util.ServiceHelper; |
25 | 24 |
|
26 | 25 | import java.util.Collection; |
27 | 26 | import java.util.Collections; |
|
42 | 41 | import static org.schabi.newpipe.player.mediasource.FailedMediaSource.MediaSourceResolutionException; |
43 | 42 | import static org.schabi.newpipe.player.mediasource.FailedMediaSource.StreamInfoLoadException; |
44 | 43 | import static org.schabi.newpipe.player.playqueue.PlayQueue.DEBUG; |
| 44 | +import static org.schabi.newpipe.util.ServiceHelper.getCacheExpirationMillis; |
45 | 45 |
|
46 | 46 | public class MediaSourceManager { |
47 | 47 | @NonNull |
@@ -420,34 +420,39 @@ private void maybeLoadItem(@NonNull final PlayQueueItem item) { |
420 | 420 | } |
421 | 421 |
|
422 | 422 | private Single<ManagedMediaSource> getLoadedMediaSource(@NonNull final PlayQueueItem stream) { |
423 | | - return stream.getStream().map(streamInfo -> { |
424 | | - final var source = playbackListener.sourceOf(stream, streamInfo); |
425 | | - |
426 | | - return Optional.ofNullable(source) |
427 | | - .flatMap(source1 -> MediaItemTag.from(source1.getMediaItem())) |
428 | | - .<ManagedMediaSource>map(tag -> { |
429 | | - final long expiration = System.currentTimeMillis() |
430 | | - + ServiceHelper.getCacheExpirationMillis(streamInfo.getServiceId()); |
431 | | - return new LoadedMediaSource(source, tag, stream, expiration); |
432 | | - }) |
433 | | - .orElseGet(() -> { |
434 | | - final String message = "Unable to resolve source from stream info. " |
435 | | - + "URL: " + stream.getUrl() + ", " |
436 | | - + "audio count: " + streamInfo.getAudioStreams().size() + ", " |
437 | | - + "video count: " + streamInfo.getVideoOnlyStreams().size() + ", " |
438 | | - + streamInfo.getVideoStreams().size(); |
439 | | - return FailedMediaSource.of(stream, new MediaSourceResolutionException( |
440 | | - message)); |
441 | | - }); |
442 | | - }).onErrorReturn(throwable -> { |
443 | | - if (throwable instanceof ExtractionException) { |
444 | | - return FailedMediaSource.of(stream, new StreamInfoLoadException(throwable)); |
445 | | - } |
446 | | - // Non-source related error expected here (e.g. network), |
447 | | - // should allow retry shortly after the error. |
448 | | - return FailedMediaSource.of(stream, new Exception(throwable), |
449 | | - /*allowRetryIn=*/TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS)); |
450 | | - }); |
| 423 | + return stream.getStream() |
| 424 | + .map(streamInfo -> Optional |
| 425 | + .ofNullable(playbackListener.sourceOf(stream, streamInfo)) |
| 426 | + .<ManagedMediaSource>flatMap(source -> |
| 427 | + MediaItemTag.from(source.getMediaItem()) |
| 428 | + .map(tag -> { |
| 429 | + final int serviceId = streamInfo.getServiceId(); |
| 430 | + final long expiration = System.currentTimeMillis() |
| 431 | + + getCacheExpirationMillis(serviceId); |
| 432 | + return new LoadedMediaSource(source, tag, stream, |
| 433 | + expiration); |
| 434 | + }) |
| 435 | + ) |
| 436 | + .orElseGet(() -> { |
| 437 | + final String message = "Unable to resolve source from stream info. " |
| 438 | + + "URL: " + stream.getUrl() |
| 439 | + + ", audio count: " + streamInfo.getAudioStreams().size() |
| 440 | + + ", video count: " + streamInfo.getVideoOnlyStreams().size() |
| 441 | + + ", " + streamInfo.getVideoStreams().size(); |
| 442 | + return FailedMediaSource.of(stream, |
| 443 | + new MediaSourceResolutionException(message)); |
| 444 | + }) |
| 445 | + ) |
| 446 | + .onErrorReturn(throwable -> { |
| 447 | + if (throwable instanceof ExtractionException) { |
| 448 | + return FailedMediaSource.of(stream, new StreamInfoLoadException(throwable)); |
| 449 | + } |
| 450 | + // Non-source related error expected here (e.g. network), |
| 451 | + // should allow retry shortly after the error. |
| 452 | + final long allowRetryIn = TimeUnit.MILLISECONDS.convert(3, |
| 453 | + TimeUnit.SECONDS); |
| 454 | + return FailedMediaSource.of(stream, new Exception(throwable), allowRetryIn); |
| 455 | + }); |
451 | 456 | } |
452 | 457 |
|
453 | 458 | private void onMediaSourceReceived(@NonNull final PlayQueueItem item, |
|
0 commit comments