1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 00:20:32 +00:00

Apply code review suggestions.

This commit is contained in:
Isira Seneviratne 2023-01-04 05:42:09 +05:30
parent e3062d7c66
commit e8216b2e80
2 changed files with 35 additions and 29 deletions

View File

@ -2056,6 +2056,7 @@ public final class Player implements PlaybackListener, Listener {
setRecovery(); setRecovery();
}, () -> { }, () -> {
// This is executed when the current stream info is not available.
reloadPlayQueueManager(); reloadPlayQueueManager();
setRecovery(); setRecovery();
}); });

View File

@ -21,7 +21,6 @@ import org.schabi.newpipe.player.playqueue.events.MoveEvent;
import org.schabi.newpipe.player.playqueue.events.PlayQueueEvent; import org.schabi.newpipe.player.playqueue.events.PlayQueueEvent;
import org.schabi.newpipe.player.playqueue.events.RemoveEvent; import org.schabi.newpipe.player.playqueue.events.RemoveEvent;
import org.schabi.newpipe.player.playqueue.events.ReorderEvent; import org.schabi.newpipe.player.playqueue.events.ReorderEvent;
import org.schabi.newpipe.util.ServiceHelper;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -42,6 +41,7 @@ import io.reactivex.rxjava3.subjects.PublishSubject;
import static org.schabi.newpipe.player.mediasource.FailedMediaSource.MediaSourceResolutionException; import static org.schabi.newpipe.player.mediasource.FailedMediaSource.MediaSourceResolutionException;
import static org.schabi.newpipe.player.mediasource.FailedMediaSource.StreamInfoLoadException; import static org.schabi.newpipe.player.mediasource.FailedMediaSource.StreamInfoLoadException;
import static org.schabi.newpipe.player.playqueue.PlayQueue.DEBUG; import static org.schabi.newpipe.player.playqueue.PlayQueue.DEBUG;
import static org.schabi.newpipe.util.ServiceHelper.getCacheExpirationMillis;
public class MediaSourceManager { public class MediaSourceManager {
@NonNull @NonNull
@ -420,34 +420,39 @@ public class MediaSourceManager {
} }
private Single<ManagedMediaSource> getLoadedMediaSource(@NonNull final PlayQueueItem stream) { private Single<ManagedMediaSource> getLoadedMediaSource(@NonNull final PlayQueueItem stream) {
return stream.getStream().map(streamInfo -> { return stream.getStream()
final var source = playbackListener.sourceOf(stream, streamInfo); .map(streamInfo -> Optional
.ofNullable(playbackListener.sourceOf(stream, streamInfo))
return Optional.ofNullable(source) .<ManagedMediaSource>flatMap(source ->
.flatMap(source1 -> MediaItemTag.from(source1.getMediaItem())) MediaItemTag.from(source.getMediaItem())
.<ManagedMediaSource>map(tag -> { .map(tag -> {
final long expiration = System.currentTimeMillis() final int serviceId = streamInfo.getServiceId();
+ ServiceHelper.getCacheExpirationMillis(streamInfo.getServiceId()); final long expiration = System.currentTimeMillis()
return new LoadedMediaSource(source, tag, stream, expiration); + getCacheExpirationMillis(serviceId);
}) return new LoadedMediaSource(source, tag, stream,
.orElseGet(() -> { expiration);
final String message = "Unable to resolve source from stream info. " })
+ "URL: " + stream.getUrl() + ", " )
+ "audio count: " + streamInfo.getAudioStreams().size() + ", " .orElseGet(() -> {
+ "video count: " + streamInfo.getVideoOnlyStreams().size() + ", " final String message = "Unable to resolve source from stream info. "
+ streamInfo.getVideoStreams().size(); + "URL: " + stream.getUrl()
return FailedMediaSource.of(stream, new MediaSourceResolutionException( + ", audio count: " + streamInfo.getAudioStreams().size()
message)); + ", video count: " + streamInfo.getVideoOnlyStreams().size()
}); + ", " + streamInfo.getVideoStreams().size();
}).onErrorReturn(throwable -> { return FailedMediaSource.of(stream,
if (throwable instanceof ExtractionException) { new MediaSourceResolutionException(message));
return FailedMediaSource.of(stream, new StreamInfoLoadException(throwable)); })
} )
// Non-source related error expected here (e.g. network), .onErrorReturn(throwable -> {
// should allow retry shortly after the error. if (throwable instanceof ExtractionException) {
return FailedMediaSource.of(stream, new Exception(throwable), return FailedMediaSource.of(stream, new StreamInfoLoadException(throwable));
/*allowRetryIn=*/TimeUnit.MILLISECONDS.convert(3, TimeUnit.SECONDS)); }
}); // Non-source related error expected here (e.g. network),
// should allow retry shortly after the error.
final long allowRetryIn = TimeUnit.MILLISECONDS.convert(3,
TimeUnit.SECONDS);
return FailedMediaSource.of(stream, new Exception(throwable), allowRetryIn);
});
} }
private void onMediaSourceReceived(@NonNull final PlayQueueItem item, private void onMediaSourceReceived(@NonNull final PlayQueueItem item,