Skip to content

Commit

Permalink
feat: Default Hls Video Quality
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Nov 25, 2024
1 parent 17d158d commit 0562204
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -401,9 +403,46 @@ public void preparePlayer(ArrayList<Quality> qualities, Quality select) {
}
}

public static Quality getDefaultSavedQualityInt(ArrayList<Quality> 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<Quality> 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<Quality> 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<Quality> qualities, long did, int mid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ object NaConfig {
ConfigItem.configTypeBool,
false
)
val defaultHlsVideoQuality =
addConfig(
"DefaultHlsVideoQuality",
ConfigItem.configTypeInt,
0
)

private fun addConfig(
k: String,
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@
<string name="PanguInfo">使文字更具可读性。在 CJK(中文、日文、韩文)、半宽英文、数字和符号字符之间间隔中自动插入空格</string>
<string name="SendWithPangu">使用 Pangu 发送</string>
<string name="SendWithoutPangu">不使用 Pangu 发送</string>
<string name="DefaultHlsVideoQuality">默认 Hls 视频质量</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@
<string name="PanguInfo">Paranoid text spacing for good readability, to automatically insert whitespace between CJK (Chinese, Japanese, Korean), half-width English, digit and symbol characters.</string>
<string name="SendWithPangu">Send with Pangu</string>
<string name="SendWithoutPangu">Send without Pangu</string>
<string name="DefaultHlsVideoQuality">Default Hls Video Quality</string>
</resources>

0 comments on commit 0562204

Please sign in to comment.