mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 11:02:35 +01:00
Resolver: Cleaned up `isVideoStreamVideoOnly
`
* Replaced by ``wasLastResolvedVideoAndAudioSeparated`` * Uses an ``Optional`` instead (we can't determine if the video and audio streams are separated when we did not fetch it)
This commit is contained in:
parent
a489f40b76
commit
bb27bf9d34
@ -3293,7 +3293,8 @@ public final class Player implements
|
||||
if (audioPlayerSelected()) {
|
||||
return audioResolver.resolve(info);
|
||||
} else {
|
||||
if (isAudioOnly && !videoResolver.isVideoStreamVideoOnly()) {
|
||||
if (isAudioOnly
|
||||
&& !videoResolver.wasLastResolvedVideoAndAudioSeparated().orElse(false)) {
|
||||
return audioResolver.resolve(info);
|
||||
}
|
||||
|
||||
@ -4189,8 +4190,9 @@ public final class Player implements
|
||||
|
||||
final boolean isVideoStreamTypeAndIsVideoOnlyStreamOrNoAudioStreamsAvailable =
|
||||
(streamType == StreamType.VIDEO_STREAM || streamType == StreamType.LIVE_STREAM)
|
||||
&& (videoResolver.isVideoStreamVideoOnly()
|
||||
&& (videoResolver.wasLastResolvedVideoAndAudioSeparated().orElse(false)
|
||||
|| isNullOrEmpty(info.getAudioStreams()));
|
||||
|
||||
if (videoRenderIndex != RENDERER_UNAVAILABLE
|
||||
&& isVideoStreamTypeAndIsVideoOnlyStreamOrNoAudioStreamsAvailable) {
|
||||
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
|
||||
|
@ -44,9 +44,4 @@ public class AudioPlaybackResolver implements PlaybackResolver {
|
||||
return buildMediaSource(dataSource, audio.getUrl(), PlayerHelper.cacheKeyOf(info, audio),
|
||||
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVideoStreamVideoOnly() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,4 @@ import androidx.annotation.Nullable;
|
||||
public interface Resolver<Source, Product> {
|
||||
@Nullable
|
||||
Product resolve(@NonNull Source source);
|
||||
|
||||
boolean isVideoStreamVideoOnly();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.schabi.newpipe.util.ListHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.google.android.exoplayer2.C.TIME_UNSET;
|
||||
|
||||
@ -35,7 +36,7 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||
@Nullable
|
||||
private String playbackQuality;
|
||||
|
||||
private boolean isVideoStreamVideoOnly = false;
|
||||
private Boolean wasLastResolvedVideoAndAudioSeparated;
|
||||
|
||||
public VideoPlaybackResolver(@NonNull final Context context,
|
||||
@NonNull final PlayerDataSource dataSource,
|
||||
@ -48,7 +49,8 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||
@Override
|
||||
@Nullable
|
||||
public MediaSource resolve(@NonNull final StreamInfo info) {
|
||||
isVideoStreamVideoOnly = false;
|
||||
boolean isVideoAndAudioSeparated = false;
|
||||
try {
|
||||
final MediaSource liveSource = maybeBuildLiveMediaSource(dataSource, info);
|
||||
if (liveSource != null) {
|
||||
return liveSource;
|
||||
@ -88,7 +90,7 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||
PlayerHelper.cacheKeyOf(info, audio),
|
||||
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
||||
mediaSources.add(audioSource);
|
||||
isVideoStreamVideoOnly = true;
|
||||
isVideoAndAudioSeparated = true;
|
||||
}
|
||||
|
||||
// If there is no audio or video sources, then this media source cannot be played back
|
||||
@ -120,11 +122,20 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||
return new MergingMediaSource(mediaSources.toArray(
|
||||
new MediaSource[0]));
|
||||
}
|
||||
} finally {
|
||||
wasLastResolvedVideoAndAudioSeparated = isVideoAndAudioSeparated;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVideoStreamVideoOnly() {
|
||||
return isVideoStreamVideoOnly;
|
||||
/**
|
||||
* Determines if the last resolved StreamInfo had separated audio and video streams
|
||||
* (or only audio).
|
||||
*
|
||||
* @return {@link Optional#empty()} if nothing was resolved
|
||||
* otherwise <code>true</code> or <code>false</code>
|
||||
*/
|
||||
public Optional<Boolean> wasLastResolvedVideoAndAudioSeparated() {
|
||||
return Optional.ofNullable(wasLastResolvedVideoAndAudioSeparated);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
Loading…
Reference in New Issue
Block a user