diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/VideoPlayer.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/VideoPlayer.java index 6627c6f4ac..07257025d0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/VideoPlayer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/VideoPlayer.java @@ -102,6 +102,8 @@ import java.util.HashMap; import java.util.HashSet; +import xyz.nextalone.nagram.NaConfig; + @SuppressLint("NewApi") public class VideoPlayer implements Player.Listener, VideoListener, AnalyticsListener, NotificationCenter.NotificationCenterDelegate { @@ -401,9 +403,46 @@ public void preparePlayer(ArrayList qualities, Quality select) { } } + public static Quality getDefaultSavedQualityInt(ArrayList qualities, int pL, int p) { + for (Quality q : qualities) { + if (!q.original && q.p() <= pL && q.p() >= p) return q; + } + return null; + } + + public static Quality getDefaultSavedQuality(ArrayList qualities) { + int v = NaConfig.INSTANCE.getDefaultHlsVideoQuality().Int(); + Quality q1; + switch (v) { + case 0: + return null; + case 1: + for (Quality q : qualities) { + if (q.original) return q; + } + case 2: + q1 = getDefaultSavedQualityInt(qualities, Integer.MAX_VALUE, 1440); + if (q1 != null) return q1; + case 3: + q1 = getDefaultSavedQualityInt(qualities, 1440, 1000); + if (q1 != null) return q1; + case 4: + q1 = getDefaultSavedQualityInt(qualities, 1000, 700); + if (q1 != null) return q1; + case 5: + q1 = getDefaultSavedQualityInt(qualities, 700, 0); + if (q1 != null) return q1; + } + return null; + } + public static Quality getSavedQuality(ArrayList qualities, MessageObject messageObject) { - if (messageObject == null) return null; - return getSavedQuality(qualities, messageObject.getDialogId(), messageObject.getId()); + if (messageObject == null) return getDefaultSavedQuality(qualities); + var q = getSavedQuality(qualities, messageObject.getDialogId(), messageObject.getId()); + if (q == null) { + return getDefaultSavedQuality(qualities); + } + return q; } public static Quality getSavedQuality(ArrayList qualities, long did, int mid) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index 2ec8a5c899..37cbda544b 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -133,6 +133,15 @@ public class NekoGeneralSettingsActivity extends BaseNekoXSettingsActivity { // private final AbstractConfigCell customPublicProxyIPRow = cellGroup.appendCell(new ConfigCellTextDetail(NekoConfig.customPublicProxyIP, (view, position) -> { // customDialog_BottomInputString(position, NekoConfig.customPublicProxyIP, LocaleController.getString("customPublicProxyIPNotice"), "IP"); // }, LocaleController.getString("UsernameEmpty", R.string.UsernameEmpty))); +private final AbstractConfigCell defaultHlsVideoQualityRow = cellGroup.appendCell(new ConfigCellSelectBox(null, NaConfig.INSTANCE.getDefaultHlsVideoQuality(), + new String[]{ + LocaleController.getString(R.string.QualityAuto), + LocaleController.getString(R.string.QualityOriginal), + LocaleController.getString(R.string.Quality1440), + LocaleController.getString(R.string.Quality1080), + LocaleController.getString(R.string.Quality720), + LocaleController.getString(R.string.Quality144), + }, null)); private final AbstractConfigCell dividerConnection = cellGroup.appendCell(new ConfigCellDivider()); private final AbstractConfigCell headerFolder = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("Folder"))); diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index c1587dbd0e..a50512d955 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -652,6 +652,12 @@ object NaConfig { ConfigItem.configTypeBool, false ) + val defaultHlsVideoQuality = + addConfig( + "DefaultHlsVideoQuality", + ConfigItem.configTypeInt, + 0 + ) private fun addConfig( k: String, diff --git a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml index 3057b8aa7c..3a45c9a058 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -165,4 +165,5 @@ 使文字更具可读性。在 CJK(中文、日文、韩文)、半宽英文、数字和符号字符之间间隔中自动插入空格 使用 Pangu 发送 不使用 Pangu 发送 + 默认 Hls 视频质量 diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index f0e9d853e3..9564d4b69c 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -166,4 +166,5 @@ Paranoid text spacing for good readability, to automatically insert whitespace between CJK (Chinese, Japanese, Korean), half-width English, digit and symbol characters. Send with Pangu Send without Pangu + Default Hls Video Quality