mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-02-06 06:40:36 -06:00
player: add zoom percents option
This commit is contained in:
@@ -59,6 +59,7 @@ public interface PlaybackEngine {
|
||||
void setVolume(float volume);
|
||||
float getVolume();
|
||||
void setVideoZoomMode(int mode);
|
||||
void setVideoZoom(int percents);
|
||||
int getVideoZoomMode();
|
||||
void setVideoAspectRatio(float mode);
|
||||
void setVideoRotation(int angle);
|
||||
|
||||
@@ -82,6 +82,7 @@ public class PlayerUIManager extends PlayerEventListenerHelper implements Metada
|
||||
|
||||
// Could be set once per activity creation (view layout stuff)
|
||||
getController().setVideoZoomMode(mPlayerData.getVideoZoomMode());
|
||||
getController().setVideoZoom(mPlayerData.getVideoZoom());
|
||||
getController().setVideoAspectRatio(mPlayerData.getVideoAspectRatio());
|
||||
getController().setVideoRotation(mPlayerData.getVideoRotation());
|
||||
}
|
||||
@@ -449,7 +450,11 @@ public class PlayerUIManager extends PlayerEventListenerHelper implements Metada
|
||||
@Override
|
||||
public void onVideoZoomClicked() {
|
||||
OptionCategory videoZoomCategory = AppDialogUtil.createVideoZoomCategory(
|
||||
getActivity(), mPlayerData, () -> getController().setVideoZoomMode(mPlayerData.getVideoZoomMode()));
|
||||
getActivity(), mPlayerData, () -> {
|
||||
getController().setVideoZoomMode(mPlayerData.getVideoZoomMode());
|
||||
getController().setVideoZoom(mPlayerData.getVideoZoom());
|
||||
getController().showControls(false);
|
||||
});
|
||||
|
||||
OptionCategory videoAspectCategory = AppDialogUtil.createVideoAspectCategory(
|
||||
getActivity(), mPlayerData, () -> getController().setVideoAspectRatio(mPlayerData.getVideoAspectRatio()));
|
||||
|
||||
@@ -47,6 +47,7 @@ public class PlayerData extends DataChangeBase {
|
||||
private final Map<String, FormatItem> mDefaultVideoFormats = new HashMap<>();
|
||||
private int mSubtitleStyleIndex;
|
||||
private int mVideoZoomMode;
|
||||
private int mVideoZoom;
|
||||
private float mVideoAspectRatio;
|
||||
private int mVideoRotation;
|
||||
private int mSeekPreviewMode;
|
||||
@@ -420,6 +421,15 @@ public class PlayerData extends DataChangeBase {
|
||||
return mVideoZoomMode;
|
||||
}
|
||||
|
||||
public void setVideoZoom(int percents) {
|
||||
mVideoZoom = percents;
|
||||
persistState();
|
||||
}
|
||||
|
||||
public int getVideoZoom() {
|
||||
return mVideoZoom;
|
||||
}
|
||||
|
||||
public void setVideoAspectRatio(float ratio) {
|
||||
mVideoAspectRatio = ratio;
|
||||
persistState();
|
||||
@@ -615,6 +625,7 @@ public class PlayerData extends DataChangeBase {
|
||||
mLastSubtitleFormat = Helpers.firstNonNull(ExoFormatItem.from(Helpers.parseStr(split, 47)), FormatItem.SUBTITLE_DEFAULT);
|
||||
mLastSpeed = Helpers.parseFloat(split, 48, 1.0f);
|
||||
mVideoRotation = Helpers.parseInt(split, 49, 0);
|
||||
mVideoZoom = Helpers.parseInt(split, 50, -1);
|
||||
|
||||
if (!mIsRememberSpeedEnabled) {
|
||||
mSpeed = 1.0f;
|
||||
@@ -623,7 +634,8 @@ public class PlayerData extends DataChangeBase {
|
||||
|
||||
@Override
|
||||
protected void persistState() {
|
||||
mPrefs.setData(VIDEO_PLAYER_DATA, Helpers.mergeObject(mOKButtonBehavior, mUIHideTimeoutSec, mIsAbsoluteDateEnabled, mSeekPreviewMode, mIsSeekConfirmPauseEnabled,
|
||||
mPrefs.setData(VIDEO_PLAYER_DATA, Helpers.mergeObject(mOKButtonBehavior, mUIHideTimeoutSec, mIsAbsoluteDateEnabled,
|
||||
mSeekPreviewMode, mIsSeekConfirmPauseEnabled,
|
||||
mIsClockEnabled, mIsRemainingTimeEnabled, mBackgroundMode, null, // afrData was there
|
||||
Helpers.toString(mVideoFormat), Helpers.toString(mAudioFormat), Helpers.toString(mSubtitleFormat),
|
||||
mVideoBufferType, mSubtitleStyleIndex, mVideoZoomMode, mSpeed,
|
||||
@@ -633,7 +645,8 @@ public class PlayerData extends DataChangeBase {
|
||||
mIsQualityInfoEnabled, mIsRememberSpeedEachEnabled, mVideoAspectRatio, mIsGlobalClockEnabled, mIsTimeCorrectionEnabled,
|
||||
mIsGlobalEndingTimeEnabled, mIsEndingTimeEnabled, mIsDoubleRefreshRateEnabled, mIsSeekConfirmPlayEnabled,
|
||||
mStartSeekIncrementMs, null, mSubtitleScale, mPlayerVolume, mIsTooltipsEnabled, mSubtitlePosition, mIsNumberKeySeekEnabled,
|
||||
mIsSkip24RateEnabled, mAfrPauseMs, mIsLiveChatEnabled, Helpers.toString(mLastSubtitleFormat), mLastSpeed, mVideoRotation));
|
||||
mIsSkip24RateEnabled, mAfrPauseMs, mIsLiveChatEnabled, Helpers.toString(mLastSubtitleFormat), mLastSpeed, mVideoRotation,
|
||||
mVideoZoom));
|
||||
|
||||
super.persistState();
|
||||
}
|
||||
|
||||
@@ -391,9 +391,20 @@ public class AppDialogUtil {
|
||||
options.add(UiOptionItem.from(context.getString(pair[0]),
|
||||
optionItem -> {
|
||||
playerData.setVideoZoomMode(pair[1]);
|
||||
playerData.setVideoZoom(-1);
|
||||
onSelectZoomMode.run();
|
||||
},
|
||||
playerData.getVideoZoomMode() == pair[1]));
|
||||
playerData.getVideoZoomMode() == pair[1] && playerData.getVideoZoom() == -1));
|
||||
}
|
||||
|
||||
for (int zoomPercents : Helpers.range(100, 300, 25)) {
|
||||
options.add(UiOptionItem.from(String.format("%s%%", zoomPercents),
|
||||
optionItem -> {
|
||||
playerData.setVideoZoom(zoomPercents);
|
||||
playerData.setVideoZoomMode(PlaybackEngine.ZOOM_MODE_DEFAULT);
|
||||
onSelectZoomMode.run();
|
||||
},
|
||||
playerData.getVideoZoom() == zoomPercents));
|
||||
}
|
||||
|
||||
String videoZoomTitle = context.getString(R.string.video_zoom);
|
||||
|
||||
@@ -102,6 +102,7 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
|
||||
private float videoAspectRatio;
|
||||
@ResizeMode private int resizeMode;
|
||||
private int zoomPercents;
|
||||
|
||||
public AspectRatioFrameLayout(Context context) {
|
||||
this(context, /* attrs= */ null);
|
||||
@@ -110,6 +111,7 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
public AspectRatioFrameLayout(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
resizeMode = RESIZE_MODE_FIT;
|
||||
zoomPercents = -1;
|
||||
if (attrs != null) {
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
|
||||
R.styleable.AspectRatioFrameLayout, 0, 0);
|
||||
@@ -161,9 +163,19 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MODIFIED: Set video zoom in percents
|
||||
*/
|
||||
public void setZoom(int percents) {
|
||||
if (zoomPercents != percents) {
|
||||
zoomPercents = percents;
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); // Zoom 100%
|
||||
if (videoAspectRatio <= 0) {
|
||||
// Aspect ratio not set.
|
||||
return;
|
||||
@@ -176,6 +188,16 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
if (Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION) {
|
||||
// We're within the allowed tolerance.
|
||||
aspectRatioUpdateDispatcher.scheduleUpdate(videoAspectRatio, viewAspectRatio, false);
|
||||
|
||||
// MODIFIED
|
||||
if (zoomPercents > 0 && zoomPercents != 100) {
|
||||
width = (width / 100) * zoomPercents;
|
||||
height = (height / 100) * zoomPercents;
|
||||
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -205,6 +227,13 @@ public final class AspectRatioFrameLayout extends FrameLayout {
|
||||
// Ignore target aspect ratio
|
||||
break;
|
||||
}
|
||||
|
||||
// MODIFIED
|
||||
if (zoomPercents > 0 && zoomPercents != 100) {
|
||||
width = (width / 100) * zoomPercents;
|
||||
height = (height / 100) * zoomPercents;
|
||||
}
|
||||
|
||||
aspectRatioUpdateDispatcher.scheduleUpdate(videoAspectRatio, viewAspectRatio, true);
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
|
||||
|
||||
@@ -1037,6 +1037,11 @@ public class PlaybackFragment extends SeekModePlaybackFragment implements Playba
|
||||
return getResizeMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVideoZoom(int percents) {
|
||||
setZoom(percents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVideoAspectRatio(float ratio) {
|
||||
setAspectRatio(ratio);
|
||||
|
||||
@@ -79,6 +79,10 @@ public class SurfacePlaybackFragment extends PlaybackSupportFragment {
|
||||
mVideoSurfaceRoot.setResizeMode(resizeMode);
|
||||
}
|
||||
|
||||
public void setZoom(int percents) {
|
||||
mVideoSurfaceRoot.setZoom(percents);
|
||||
}
|
||||
|
||||
/** Returns the {@link ResizeMode}. */
|
||||
public @ResizeMode int getResizeMode() {
|
||||
return mVideoSurfaceRoot.getResizeMode();
|
||||
|
||||
Reference in New Issue
Block a user