Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ private void onDialogHide() {
//}

private void addPresetsCategory() {
// Per channel presets (same as the speed list)
if (getPlayerData().isFormatPerChannelEnabled() && getPlayer() != null
&& getPlayer().getVideo() != null && getPlayer().getVideo().channelId != null) {
addPresetsPerChannelCategory();
return;
}

addCategoryInt(AppDialogUtil.createVideoPresetsCategory(
getContext(), () -> {
if (getPlayer() == null) {
Expand All @@ -209,6 +216,31 @@ private void addPresetsCategory() {
));
}

private void addPresetsPerChannelCategory() {
addCategoryInt(AppDialogUtil.createVideoPresetsPerChannelCategory(
getContext(), getPlayer().getVideo().channelId, () -> {
if (getPlayer() == null || getPlayer().getVideo() == null) {
return;
}

FormatItem format = getPlayerData().getFormatPerChannel(getPlayer().getVideo().channelId);

if (format == null) {
format = getPlayerData().getFormat(FormatItem.TYPE_VIDEO);
}

getPlayer().setFormat(format);

if (!getPlayer().containsMedia()) {
getPlayer().reloadPlayback();
}

// Make result easily be spotted by the user
getPlayer().showOverlay(false);
}
));
}

private void addVideoZoomCategory() {
if (getPlayer() == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public void onMetadata(MediaItemMetadata metadata) {
// Channel info should be loaded at this point
if (getVideo() != null && !getVideo().isRemote) {
restoreSubtitleFormat();
// Channel id is set only now, so reapply the per channel format
if (getPlayerData().isFormatPerChannelEnabled() && getPlayerData().getFormatPerChannel(getVideo().channelId) != null) {
restoreVideoFormat();
}
}

// Need to contain channel id
Expand Down Expand Up @@ -403,8 +407,14 @@ private void restoreVideoFormat() {
return;
}

Video video = getPlayer().getVideo();
FormatItem formatPerChannel = getPlayerData().isFormatPerChannelEnabled() && video != null
? getPlayerData().getFormatPerChannel(video.channelId) : null;

if (getPlayerData().getTempVideoFormat() != null) {
getPlayer().setFormat(getPlayerData().getTempVideoFormat());
} else if (formatPerChannel != null) {
getPlayer().setFormat(formatPerChannel);
} else {
getPlayer().setFormat(getPlayerData().getFormat(FormatItem.TYPE_VIDEO));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ private void appendMiscCategory(AppDialogPresenter settingsPresenter) {
option -> mPlayerTweaksData.setQueueRespectsPlaybackMode(option.isSelected()),
mPlayerTweaksData.isQueueRespectsPlaybackMode()));

options.add(AppDialogUtil.createVideoPresetChannelOption(getContext()));

settingsPresenter.appendCheckedCategory(getContext().getString(R.string.player_other), options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class PlayerData extends DataChangeBase implements PlayerConstants, Profi
private boolean mIsSubtitlesPerChannelEnabled;
private boolean mIsSpeedPerChannelEnabled;
private final Map<String, SpeedItem> mSpeeds = new HashMap<>();
private final Map<String, ChannelFormat> mFormatsPerChannel = new HashMap<>();
private boolean mIsFormatPerChannelEnabled;
private float mPitch;
private long mAfrSwitchTimeMs;
private List<String> mLastAudioLanguages;
Expand Down Expand Up @@ -128,6 +130,32 @@ public String toString() {
}
}

private static class ChannelFormat {
public String channelId;
public FormatItem format;

public ChannelFormat(String channelId, FormatItem format) {
this.channelId = channelId;
this.format = format;
}

public static ChannelFormat fromString(String specs) {
String[] split = Helpers.splitObj(specs);

if (split == null || split.length != 2) {
return new ChannelFormat(null, null);
}

return new ChannelFormat(Helpers.parseStr(split[0]), ExoFormatItem.from(Helpers.parseStr(split[1])));
}

@NonNull
@Override
public String toString() {
return Helpers.mergeObj(channelId, format);
}
}

private PlayerData(Context context) {
mPrefs = AppPrefs.instance(context);
mPrefs.addListener(this);
Expand Down Expand Up @@ -408,6 +436,39 @@ public FormatItem getTempVideoFormat() {
return mTempVideoFormat;
}

public FormatItem getFormatPerChannel(String channelId) {
if (channelId == null) {
return null;
}

ChannelFormat format = mFormatsPerChannel.get(channelId);

return format != null ? format.format : null;
}

public void setFormatPerChannel(String channelId, FormatItem format) {
if (channelId == null) {
return;
}

if (format == null) {
mFormatsPerChannel.remove(channelId);
} else {
mFormatsPerChannel.put(channelId, new ChannelFormat(channelId, format));
}

persistState();
}

public boolean isFormatPerChannelEnabled() {
return mIsFormatPerChannelEnabled;
}

public void setFormatPerChannelEnabled(boolean enable) {
mIsFormatPerChannelEnabled = enable;
persistState();
}

public FormatItem getLastSubtitleFormat() {
return !mLastSubtitleFormats.isEmpty() ? mLastSubtitleFormats.get(0) : FormatItem.SUBTITLE_NONE;
}
Expand Down Expand Up @@ -847,6 +908,8 @@ private void restoreState() {
mLastAudioLanguages = Helpers.parseStrList(split, 60);
mIsVideoFlipEnabled = Helpers.parseBoolean(split, 61, false);
mIsAudioDelayEnabled = Helpers.parseBoolean(split, 62, false);
String[] formatsPerChannel = Helpers.parseArray(split, 63);
mIsFormatPerChannelEnabled = Helpers.parseBoolean(split, 64, false);

if (speeds != null) {
for (String speedSpec : speeds) {
Expand All @@ -855,6 +918,13 @@ private void restoreState() {
}
}

if (formatsPerChannel != null) {
for (String formatSpec : formatsPerChannel) {
ChannelFormat item = ChannelFormat.fromString(formatSpec);
mFormatsPerChannel.put(item.channelId, item);
}
}

if (!mIsAllSpeedEnabled) {
mSpeed = 1.0f;
}
Expand Down Expand Up @@ -884,7 +954,8 @@ private void persistStateInt() {
mIsNumberKeySeekEnabled, mIsSkip24RateEnabled, mAfrPauseMs, mIsLiveChatEnabled, mLastSubtitleFormats, mLastSpeed, mRotationAngle,
mZoomPercents, mPlaybackMode, mAudioLanguage, mSubtitleLanguage, mEnabledSubtitlesPerChannel, mIsSubtitlesPerChannelEnabled,
mIsSpeedPerChannelEnabled, Helpers.mergeArray(mSpeeds.values().toArray()), mPitch, mIsSkipShortsEnabled, mLastAudioLanguages,
mIsVideoFlipEnabled, mIsAudioDelayEnabled
mIsVideoFlipEnabled, mIsAudioDelayEnabled, Helpers.mergeArray(mFormatsPerChannel.values().toArray()),
mIsFormatPerChannelEnabled
));
}

Expand All @@ -894,6 +965,7 @@ public void onProfileChanged() {

// reset on profile change
mSpeeds.clear();
mFormatsPerChannel.clear();

restoreState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class AppDialogUtil {
private static final int PLAYER_ENGINE_ID = 147;
private static final int IGNORE_DURATION_ID = 148;
private static final int SLEEP_TIMER_ID = 149;
private static final int VIDEO_PRESETS_PER_CHANNEL_ID = 150;
private static final int SUBTITLE_STYLES_ID = 45;
private static final int SUBTITLE_SIZE_ID = 46;
private static final int SUBTITLE_POSITION_ID = 47;
Expand Down Expand Up @@ -309,6 +310,60 @@ private static List<OptionItem> fromPresets(Context context, VideoPreset[] prese
return result;
}

public static OptionItem createVideoPresetChannelOption(Context context) {
PlayerData playerData = PlayerData.instance(context);
return UiOptionItem.from(context.getString(R.string.video_preset_per_channel),
optionItem -> playerData.setFormatPerChannelEnabled(optionItem.isSelected()),
playerData.isFormatPerChannelEnabled()
);
}

public static OptionCategory createVideoPresetsPerChannelCategory(Context context, String channelId, Runnable onFormatSelected) {
return OptionCategory.from(
VIDEO_PRESETS_PER_CHANNEL_ID,
OptionCategory.TYPE_RADIO_LIST,
context.getString(R.string.title_video_presets),
fromChannelPresets(
context,
AppDataSourceManager.instance().getVideoPresets(),
channelId,
onFormatSelected
)
);
}

private static List<OptionItem> fromChannelPresets(Context context, VideoPreset[] presets, String channelId, Runnable onFormatSelected) {
List<OptionItem> result = new ArrayList<>();

PlayerData playerData = PlayerData.instance(context);
PlayerTweaksData playerTweaksData = PlayerTweaksData.instance(context);
FormatItem selectedFormat = playerData.getFormatPerChannel(channelId);
boolean isAllFormatsUnlocked = playerTweaksData.isAllFormatsUnlocked();

for (VideoPreset preset : presets) {
if (!isAllFormatsUnlocked && !Utils.isPresetSupported(preset)) {
continue;
}

result.add(0, UiOptionItem.from(preset.name,
option -> {
playerData.setFormatPerChannel(channelId, preset.format);
onFormatSelected.run();
},
preset.format.equals(selectedFormat)));
}

result.add(0, UiOptionItem.from(
context.getString(R.string.option_disabled),
optionItem -> {
playerData.setFormatPerChannel(channelId, null);
onFormatSelected.run();
},
selectedFormat == null));

return result;
}

public static OptionCategory createVideoBufferCategory(Context context) {
return createVideoBufferCategory(context, () -> {});
}
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="msg_signed_users_only">Signed users only</string>
<string name="msg_cant_load_content">Can\'t load content.\n1) Turn on watch history.\n2) Check date and time on the device.\n3) Check network connection.\n4) Check your proxy settings.\n5) Try to sign in to your account.\n6) Maybe there is nothing in here.</string>
<string name="title_video_presets">Video presets</string>
<string name="video_preset_per_channel">Remember video preset per channel</string>
<string name="settings_accounts">Accounts</string>
<string name="settings_left_panel">Edit categories</string>
<string name="settings_themes">Themes</string>
Expand Down