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()) {
|
if (audioPlayerSelected()) {
|
||||||
return audioResolver.resolve(info);
|
return audioResolver.resolve(info);
|
||||||
} else {
|
} else {
|
||||||
if (isAudioOnly && !videoResolver.isVideoStreamVideoOnly()) {
|
if (isAudioOnly
|
||||||
|
&& !videoResolver.wasLastResolvedVideoAndAudioSeparated().orElse(false)) {
|
||||||
return audioResolver.resolve(info);
|
return audioResolver.resolve(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4189,8 +4190,9 @@ public final class Player implements
|
||||||
|
|
||||||
final boolean isVideoStreamTypeAndIsVideoOnlyStreamOrNoAudioStreamsAvailable =
|
final boolean isVideoStreamTypeAndIsVideoOnlyStreamOrNoAudioStreamsAvailable =
|
||||||
(streamType == StreamType.VIDEO_STREAM || streamType == StreamType.LIVE_STREAM)
|
(streamType == StreamType.VIDEO_STREAM || streamType == StreamType.LIVE_STREAM)
|
||||||
&& (videoResolver.isVideoStreamVideoOnly()
|
&& (videoResolver.wasLastResolvedVideoAndAudioSeparated().orElse(false)
|
||||||
|| isNullOrEmpty(info.getAudioStreams()));
|
|| isNullOrEmpty(info.getAudioStreams()));
|
||||||
|
|
||||||
if (videoRenderIndex != RENDERER_UNAVAILABLE
|
if (videoRenderIndex != RENDERER_UNAVAILABLE
|
||||||
&& isVideoStreamTypeAndIsVideoOnlyStreamOrNoAudioStreamsAvailable) {
|
&& isVideoStreamTypeAndIsVideoOnlyStreamOrNoAudioStreamsAvailable) {
|
||||||
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
|
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
|
||||||
|
|
|
@ -44,9 +44,4 @@ public class AudioPlaybackResolver implements PlaybackResolver {
|
||||||
return buildMediaSource(dataSource, audio.getUrl(), PlayerHelper.cacheKeyOf(info, audio),
|
return buildMediaSource(dataSource, audio.getUrl(), PlayerHelper.cacheKeyOf(info, audio),
|
||||||
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVideoStreamVideoOnly() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,4 @@ import androidx.annotation.Nullable;
|
||||||
public interface Resolver<Source, Product> {
|
public interface Resolver<Source, Product> {
|
||||||
@Nullable
|
@Nullable
|
||||||
Product resolve(@NonNull Source source);
|
Product resolve(@NonNull Source source);
|
||||||
|
|
||||||
boolean isVideoStreamVideoOnly();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.schabi.newpipe.util.ListHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.C.TIME_UNSET;
|
import static com.google.android.exoplayer2.C.TIME_UNSET;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||||
@Nullable
|
@Nullable
|
||||||
private String playbackQuality;
|
private String playbackQuality;
|
||||||
|
|
||||||
private boolean isVideoStreamVideoOnly = false;
|
private Boolean wasLastResolvedVideoAndAudioSeparated;
|
||||||
|
|
||||||
public VideoPlaybackResolver(@NonNull final Context context,
|
public VideoPlaybackResolver(@NonNull final Context context,
|
||||||
@NonNull final PlayerDataSource dataSource,
|
@NonNull final PlayerDataSource dataSource,
|
||||||
|
@ -48,7 +49,8 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public MediaSource resolve(@NonNull final StreamInfo info) {
|
public MediaSource resolve(@NonNull final StreamInfo info) {
|
||||||
isVideoStreamVideoOnly = false;
|
boolean isVideoAndAudioSeparated = false;
|
||||||
|
try {
|
||||||
final MediaSource liveSource = maybeBuildLiveMediaSource(dataSource, info);
|
final MediaSource liveSource = maybeBuildLiveMediaSource(dataSource, info);
|
||||||
if (liveSource != null) {
|
if (liveSource != null) {
|
||||||
return liveSource;
|
return liveSource;
|
||||||
|
@ -88,7 +90,7 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
||||||
PlayerHelper.cacheKeyOf(info, audio),
|
PlayerHelper.cacheKeyOf(info, audio),
|
||||||
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
||||||
mediaSources.add(audioSource);
|
mediaSources.add(audioSource);
|
||||||
isVideoStreamVideoOnly = true;
|
isVideoAndAudioSeparated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no audio or video sources, then this media source cannot be played back
|
// 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(
|
return new MergingMediaSource(mediaSources.toArray(
|
||||||
new MediaSource[0]));
|
new MediaSource[0]));
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
wasLastResolvedVideoAndAudioSeparated = isVideoAndAudioSeparated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public boolean isVideoStreamVideoOnly() {
|
* Determines if the last resolved StreamInfo had separated audio and video streams
|
||||||
return isVideoStreamVideoOnly;
|
* (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
|
@Nullable
|
||||||
|
|
Loading…
Reference in New Issue