From b0a4ce167e483fe20377236d5904e408771f7ed1 Mon Sep 17 00:00:00 2001 From: jaro Date: Thu, 2 Jun 2022 21:25:33 +0200 Subject: [PATCH 1/2] add aspect ratio toggle button in exoplayer --- .../java/com/github/libretube/PlayerFragment.kt | 13 +++++++++++++ app/src/main/res/drawable/ic_aspect_ratio.xml | 5 +++++ .../layout/exo_styled_player_control_view.xml | 16 +++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/ic_aspect_ratio.xml diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index 4f86f9c53..e22529ece 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -65,6 +65,7 @@ import com.google.android.exoplayer2.source.DefaultMediaSourceFactory import com.google.android.exoplayer2.source.MediaSource import com.google.android.exoplayer2.source.MergingMediaSource import com.google.android.exoplayer2.source.ProgressiveMediaSource +import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.ui.PlayerNotificationManager import com.google.android.exoplayer2.ui.StyledPlayerView import com.google.android.exoplayer2.upstream.DataSource @@ -93,6 +94,7 @@ class PlayerFragment : Fragment() { private var eId: Int = 0 private var paused = false private var whichQuality = 0 + private var isZoomed: Boolean = false var isSubscribed: Boolean = false @@ -283,6 +285,17 @@ class PlayerFragment : Fragment() { } } + // switching between original aspect ratio (black bars) and zoomed to fill device screen + view.findViewById(R.id.aspect_ratio_button).setOnClickListener { + if(isZoomed) { + exoPlayerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + isZoomed = false + } else { + exoPlayerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + isZoomed = true + } + } + val scrollView = view.findViewById(R.id.player_scrollView) scrollView.viewTreeObserver .addOnScrollChangedListener { diff --git a/app/src/main/res/drawable/ic_aspect_ratio.xml b/app/src/main/res/drawable/ic_aspect_ratio.xml new file mode 100644 index 000000000..c7b8b5f55 --- /dev/null +++ b/app/src/main/res/drawable/ic_aspect_ratio.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index 9862ce8f2..4a1a1898e 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -48,13 +48,10 @@ android:layout_height="wrap_content" android:src="@drawable/ic_close2" android:padding="@dimen/exo_icon_padding" - android:background="#00FFFFFF" - - /> + android:background="#00FFFFFF"/> + + android:textColor="#FFFFFF"/> Date: Thu, 2 Jun 2022 21:36:58 +0200 Subject: [PATCH 2/2] Update PlayerFragment.kt --- app/src/main/java/com/github/libretube/PlayerFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index e22529ece..801adf9e7 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -287,7 +287,7 @@ class PlayerFragment : Fragment() { // switching between original aspect ratio (black bars) and zoomed to fill device screen view.findViewById(R.id.aspect_ratio_button).setOnClickListener { - if(isZoomed) { + if (isZoomed) { exoPlayerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT isZoomed = false } else {