diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorManager.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorManager.java index e5cf9f3b4..4fc065b6b 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorManager.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorManager.java @@ -413,6 +413,10 @@ public class TrackSelectorManager implements TrackSelectorCallback { result = mediaTrack; } } + + if (result.format != null && TrackSelectorUtil.codecEquals(result.format.codecs, track.format.codecs)) { + break; + } } } diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java index 7b0754269..331ad44be 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/TrackSelectorUtil.java @@ -119,4 +119,12 @@ public class TrackSelectorUtil { playbackState == Player.STATE_IDLE ? "STATE_IDLE" : "STATE_ENDED"; } + + public static boolean codecEquals(String codecs1, String codecs2) { + if (codecs1 == null || codecs2 == null) { + return false; + } + + return Helpers.equals(TrackSelectorUtil.codecNameShort(codecs1), TrackSelectorUtil.codecNameShort(codecs2)); + } } diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/track/VideoTrack.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/track/VideoTrack.java index 59c0dbd7d..7c78cd1d4 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/track/VideoTrack.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/exoplayer/selector/track/VideoTrack.java @@ -54,6 +54,39 @@ public class VideoTrack extends MediaTrack { return track.format.frameRate == -1; } + //@Override + //public int compare(MediaTrack track2) { + // if (track2.format == null) { + // return 1; + // } + // + // int result = -1; + // + // if (Helpers.equals(format.id, track2.format.id)) { + // result = 0; + // } else if (codecEquals(format.codecs, track2.format.codecs)) { + // if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) { + // if (heightEquals(format.height, track2.format.height)) { + // if (TrackSelectorUtil.isHdrCodec(format.codecs) == TrackSelectorUtil.isHdrCodec(track2.format.codecs)) { + // result = 0; + // } else { + // result = 1; + // } + // } else if (heightLessOrEquals(track2.format.height, format.height)) { + // result = 1; + // } + // } + // } else if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) { + // if (heightEquals(format.height, track2.format.height)) { + // result = 2; + // } else if (heightLessOrEquals(track2.format.height, format.height)) { + // result = 2; + // } + // } + // + // return result; + //} + @Override public int compare(MediaTrack track2) { if (track2.format == null) { @@ -64,17 +97,19 @@ public class VideoTrack extends MediaTrack { if (Helpers.equals(format.id, track2.format.id)) { result = 0; - } else if (codecEquals(format.codecs, track2.format.codecs) || isLive(track2)) { - if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) { - if (heightEquals(format.height, track2.format.height)) { + } if (fpsLessOrEquals(track2.format.frameRate, format.frameRate)) { + if (heightEquals(format.height, track2.format.height)) { + if (codecEquals(format.codecs, track2.format.codecs)) { if (TrackSelectorUtil.isHdrCodec(format.codecs) == TrackSelectorUtil.isHdrCodec(track2.format.codecs)) { result = 0; } else { result = 1; } - } else if (heightLessOrEquals(track2.format.height, format.height)) { + } else { result = 1; } + } else if (heightLessOrEquals(track2.format.height, format.height)) { + result = 1; } }