From 73a65773fbcb6e6aa74676bada17a63423749db2 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Fri, 11 Aug 2023 12:33:18 +0530 Subject: [PATCH 1/5] feat: add fill resize mode to player --- .../main/res/drawable/ic_crop_landscape.xml | 5 +++++ .../src/main/res/drawable/ic_fit_screen.xml | 5 +++++ .../src/main/res/drawable/ic_width_wide.xml | 5 +++++ .../feature/player/PlayerActivity.kt | 22 ++++++++++++++----- .../res/layout/exo_player_control_view.xml | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 core/ui/src/main/res/drawable/ic_crop_landscape.xml create mode 100644 core/ui/src/main/res/drawable/ic_fit_screen.xml create mode 100644 core/ui/src/main/res/drawable/ic_width_wide.xml diff --git a/core/ui/src/main/res/drawable/ic_crop_landscape.xml b/core/ui/src/main/res/drawable/ic_crop_landscape.xml new file mode 100644 index 000000000..9b5bda1f7 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_crop_landscape.xml @@ -0,0 +1,5 @@ + + + diff --git a/core/ui/src/main/res/drawable/ic_fit_screen.xml b/core/ui/src/main/res/drawable/ic_fit_screen.xml new file mode 100644 index 000000000..33ec370ed --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_fit_screen.xml @@ -0,0 +1,5 @@ + + + diff --git a/core/ui/src/main/res/drawable/ic_width_wide.xml b/core/ui/src/main/res/drawable/ic_width_wide.xml new file mode 100644 index 000000000..f41b20e24 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_width_wide.xml @@ -0,0 +1,5 @@ + + + diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index 1c67974de..577faa41a 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -369,12 +369,24 @@ class PlayerActivity : AppCompatActivity() { } } videoZoomButton.setOnClickListener { - binding.playerView.resizeMode = - if (binding.playerView.resizeMode != AspectRatioFrameLayout.RESIZE_MODE_ZOOM) { - AspectRatioFrameLayout.RESIZE_MODE_ZOOM - } else { - AspectRatioFrameLayout.RESIZE_MODE_FIT + when(binding.playerView.resizeMode) { + AspectRatioFrameLayout.RESIZE_MODE_FIT -> { + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_aspect_ratio) + } + AspectRatioFrameLayout.RESIZE_MODE_FILL -> { + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_crop_landscape) + } + AspectRatioFrameLayout.RESIZE_MODE_ZOOM -> { + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) } + else -> { + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) + } + } } lockControlsButton.setOnClickListener { playerControls.visibility = View.INVISIBLE diff --git a/feature/player/src/main/res/layout/exo_player_control_view.xml b/feature/player/src/main/res/layout/exo_player_control_view.xml index 2ee731b4f..47923e9d5 100644 --- a/feature/player/src/main/res/layout/exo_player_control_view.xml +++ b/feature/player/src/main/res/layout/exo_player_control_view.xml @@ -189,7 +189,7 @@ android:contentDescription="@string/video_zoom" android:contextClickable="true" android:padding="12dp" - android:src="@drawable/ic_aspect_ratio" + android:src="@drawable/ic_fit_screen" app:tint="@android:color/white" /> Date: Mon, 14 Aug 2023 11:05:31 +0530 Subject: [PATCH 2/5] feat: add presistant video zoom options --- .../core/model/PlayerPreferences.kt | 1 + .../nextplayer/core/model/VideoZoom.kt | 5 ++ .../feature/player/PlayerActivity.kt | 66 ++++++++++++++----- .../feature/player/PlayerViewModel.kt | 7 ++ 4 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt diff --git a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt index f9a1ed4eb..435d4be2e 100644 --- a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt +++ b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/PlayerPreferences.kt @@ -15,6 +15,7 @@ data class PlayerPreferences( val rememberSelections: Boolean = true, val preferredAudioLanguage: String = "", val playerScreenOrientation: ScreenOrientation = ScreenOrientation.VIDEO_ORIENTATION, + val playerVideoZoom: VideoZoom = VideoZoom.BEST_FIT, val defaultPlaybackSpeed: Float = 1.0f, val controllerAutoHideTimeout: Int = 2, val seekIncrement: Int = 10, diff --git a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt new file mode 100644 index 000000000..e9234f093 --- /dev/null +++ b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt @@ -0,0 +1,5 @@ +package dev.anilbeesetti.nextplayer.core.model + +enum class VideoZoom { + BEST_FIT, STRETCH, CROP, HUNDRED_PERCENT +} \ No newline at end of file diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index 577faa41a..dae76c3c0 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -53,6 +53,7 @@ import dev.anilbeesetti.nextplayer.core.common.extensions.getPath import dev.anilbeesetti.nextplayer.core.model.DecoderPriority import dev.anilbeesetti.nextplayer.core.model.ScreenOrientation import dev.anilbeesetti.nextplayer.core.model.ThemeConfig +import dev.anilbeesetti.nextplayer.core.model.VideoZoom import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR import dev.anilbeesetti.nextplayer.feature.player.databinding.ActivityPlayerBinding import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedControlsDialogFragment @@ -106,6 +107,7 @@ class PlayerActivity : AppCompatActivity() { private var isPlayingOnScrubStart: Boolean = false private var currentOrientation: Int? = null private var currentVideoOrientation: Int? = null + private var currentVideoSize: VideoSize? = null private val shouldFastSeek: Boolean get() = playerPreferences.shouldFastSeek(player.duration) @@ -138,6 +140,7 @@ class PlayerActivity : AppCompatActivity() { */ private lateinit var audioTrackButton: ImageButton private lateinit var backButton: ImageButton + private lateinit var exoContentFrameLayout: AspectRatioFrameLayout private lateinit var lockControlsButton: ImageButton private lateinit var nextButton: ImageButton private lateinit var playbackSpeedButton: ImageButton @@ -180,6 +183,7 @@ class PlayerActivity : AppCompatActivity() { // Initializing views audioTrackButton = binding.playerView.findViewById(R.id.btn_audio_track) backButton = binding.playerView.findViewById(R.id.back_button) + exoContentFrameLayout = binding.playerView.findViewById(R.id.exo_content_frame) lockControlsButton = binding.playerView.findViewById(R.id.btn_lock_controls) nextButton = binding.playerView.findViewById(R.id.btn_play_next) playbackSpeedButton = binding.playerView.findViewById(R.id.btn_playback_speed) @@ -369,24 +373,9 @@ class PlayerActivity : AppCompatActivity() { } } videoZoomButton.setOnClickListener { - when(binding.playerView.resizeMode) { - AspectRatioFrameLayout.RESIZE_MODE_FIT -> { - binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL - videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_aspect_ratio) - } - AspectRatioFrameLayout.RESIZE_MODE_FILL -> { - binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM - videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_crop_landscape) - } - AspectRatioFrameLayout.RESIZE_MODE_ZOOM -> { - binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT - videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) - } - else -> { - binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT - videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) - } - } + val videoZoom = playerPreferences.playerVideoZoom.next() + viewModel.setVideoZoom(videoZoom) + applyVideoZoom(videoZoom) } lockControlsButton.setOnClickListener { playerControls.visibility = View.INVISIBLE @@ -495,6 +484,9 @@ class PlayerActivity : AppCompatActivity() { @SuppressLint("SourceLockedOrientationActivity") override fun onVideoSizeChanged(videoSize: VideoSize) { + currentVideoSize = videoSize + applyVideoZoom(playerPreferences.playerVideoZoom) + if (currentOrientation != null) return if (playerPreferences.playerScreenOrientation == ScreenOrientation.VIDEO_ORIENTATION) { @@ -669,6 +661,38 @@ class PlayerActivity : AppCompatActivity() { }.build() } } + + + private fun applyVideoZoom(videoZoom: VideoZoom) { + when(videoZoom) { + VideoZoom.BEST_FIT -> { + exoContentFrameLayout.layoutParams.width = binding.playerView.width + exoContentFrameLayout.layoutParams.height = binding.playerView.height + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) + } + VideoZoom.STRETCH -> { + exoContentFrameLayout.layoutParams.width = binding.playerView.width + exoContentFrameLayout.layoutParams.height = binding.playerView.height + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_aspect_ratio) + } + VideoZoom.CROP -> { + exoContentFrameLayout.layoutParams.width = binding.playerView.width + exoContentFrameLayout.layoutParams.height = binding.playerView.height + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_crop_landscape) + } + VideoZoom.HUNDRED_PERCENT -> { + currentVideoSize?.let { + exoContentFrameLayout.layoutParams.width = it.width + exoContentFrameLayout.layoutParams.height = it.height + } + binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT + videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_width_wide) + } + } + } } private val VideoSize.isPortrait: Boolean @@ -717,3 +741,9 @@ fun Activity.prettyPrintIntent() { } } } + +inline fun > T.next(): T { + val values = enumValues() + val nextOrdinal = (ordinal + 1) % values.size + return values[nextOrdinal] +} \ No newline at end of file diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt index 17db3857e..b6e9367cc 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt @@ -12,6 +12,7 @@ import dev.anilbeesetti.nextplayer.core.domain.GetSortedPlaylistUseCase import dev.anilbeesetti.nextplayer.core.model.ApplicationPreferences import dev.anilbeesetti.nextplayer.core.model.PlayerPreferences import dev.anilbeesetti.nextplayer.core.model.Resume +import dev.anilbeesetti.nextplayer.core.model.VideoZoom import javax.inject.Inject import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.stateIn @@ -102,6 +103,12 @@ class PlayerViewModel @Inject constructor( } } + fun setVideoZoom(videoZoom: VideoZoom) { + viewModelScope.launch { + preferencesRepository.updatePlayerPreferences { it.copy(playerVideoZoom = videoZoom) } + } + } + fun resetAllToDefaults() { currentPlaybackPosition = null currentPlaybackSpeed = 1f From e9a6ba991190251af1cac833d104a1eac8a7eb76 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Mon, 14 Aug 2023 11:34:22 +0530 Subject: [PATCH 3/5] feat: add video zoom options dialog --- core/ui/src/main/res/values/strings.xml | 6 ++- .../feature/player/PlayerActivity.kt | 30 +++++++++---- .../dialogs/VideoZoomOptionsDialogFragment.kt | 44 +++++++++++++++++++ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 92b80b211..de4e65b36 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -62,7 +62,7 @@ Smallest Largest Dark theme - Video Zoom + Video zoom Dynamic color theme Apply colors from system wallpaper to the application theme Lock controls @@ -141,4 +141,8 @@ The following file will be deleted permanently Subtitle text encoding All video files in the following folder will be deleted permanently. + Best fit + Stretch + Crop + 100% \ No newline at end of file diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index dae76c3c0..71483f398 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -54,10 +54,10 @@ import dev.anilbeesetti.nextplayer.core.model.DecoderPriority import dev.anilbeesetti.nextplayer.core.model.ScreenOrientation import dev.anilbeesetti.nextplayer.core.model.ThemeConfig import dev.anilbeesetti.nextplayer.core.model.VideoZoom -import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR import dev.anilbeesetti.nextplayer.feature.player.databinding.ActivityPlayerBinding import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedControlsDialogFragment import dev.anilbeesetti.nextplayer.feature.player.dialogs.TrackSelectionDialogFragment +import dev.anilbeesetti.nextplayer.feature.player.dialogs.VideoZoomOptionsDialogFragment import dev.anilbeesetti.nextplayer.feature.player.dialogs.getCurrentTrackIndex import dev.anilbeesetti.nextplayer.feature.player.extensions.audioSessionId import dev.anilbeesetti.nextplayer.feature.player.extensions.getLocalSubtitles @@ -76,12 +76,13 @@ import dev.anilbeesetti.nextplayer.feature.player.utils.PlayerApi import dev.anilbeesetti.nextplayer.feature.player.utils.PlayerGestureHelper import dev.anilbeesetti.nextplayer.feature.player.utils.PlaylistManager import dev.anilbeesetti.nextplayer.feature.player.utils.toMillis -import java.nio.charset.Charset -import java.util.Arrays import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber +import java.nio.charset.Charset +import java.util.Arrays +import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR @SuppressLint("UnsafeOptInUsageError") @AndroidEntryPoint @@ -372,11 +373,6 @@ class PlayerActivity : AppCompatActivity() { playVideo(playlistManager.getPrev()!!) } } - videoZoomButton.setOnClickListener { - val videoZoom = playerPreferences.playerVideoZoom.next() - viewModel.setVideoZoom(videoZoom) - applyVideoZoom(videoZoom) - } lockControlsButton.setOnClickListener { playerControls.visibility = View.INVISIBLE unlockControlsButton.visibility = View.VISIBLE @@ -389,6 +385,18 @@ class PlayerActivity : AppCompatActivity() { isControlsLocked = false toggleSystemBars(showBars = true) } + videoZoomButton.setOnClickListener { + val videoZoom = playerPreferences.playerVideoZoom.next() + applyVideoZoom(videoZoom) + } + + videoZoomButton.setOnLongClickListener { + VideoZoomOptionsDialogFragment( + currentVideoZoom = playerPreferences.playerVideoZoom, + onVideoZoomOptionSelected = { applyVideoZoom(it) } + ).show(supportFragmentManager, "VideoZoomOptionsDialog") + true + } screenRotationButton.setOnClickListener { requestedOrientation = when (resources.configuration.orientation) { Configuration.ORIENTATION_LANDSCAPE -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT @@ -664,25 +672,29 @@ class PlayerActivity : AppCompatActivity() { private fun applyVideoZoom(videoZoom: VideoZoom) { - when(videoZoom) { + viewModel.setVideoZoom(videoZoom) + when (videoZoom) { VideoZoom.BEST_FIT -> { exoContentFrameLayout.layoutParams.width = binding.playerView.width exoContentFrameLayout.layoutParams.height = binding.playerView.height binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) } + VideoZoom.STRETCH -> { exoContentFrameLayout.layoutParams.width = binding.playerView.width exoContentFrameLayout.layoutParams.height = binding.playerView.height binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_aspect_ratio) } + VideoZoom.CROP -> { exoContentFrameLayout.layoutParams.width = binding.playerView.width exoContentFrameLayout.layoutParams.height = binding.playerView.height binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_crop_landscape) } + VideoZoom.HUNDRED_PERCENT -> { currentVideoSize?.let { exoContentFrameLayout.layoutParams.width = it.width diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt new file mode 100644 index 000000000..b276b852a --- /dev/null +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt @@ -0,0 +1,44 @@ +package dev.anilbeesetti.nextplayer.feature.player.dialogs + +import android.app.Dialog +import android.os.Bundle +import androidx.fragment.app.DialogFragment +import androidx.media3.common.util.UnstableApi +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import dev.anilbeesetti.nextplayer.core.model.VideoZoom +import dev.anilbeesetti.nextplayer.core.ui.R + +@UnstableApi +class VideoZoomOptionsDialogFragment( + private val currentVideoZoom: VideoZoom, + private val onVideoZoomOptionSelected: (videoZoom: VideoZoom) -> Unit +) : DialogFragment() { + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + + val videoZoomValues = VideoZoom.values() + + return activity?.let { activity -> + MaterialAlertDialogBuilder(activity) + .setTitle(getString(R.string.video_zoom)) + .setSingleChoiceItems( + videoZoomValues.map { getString(it.nameRes()) }.toTypedArray(), + videoZoomValues.indexOfFirst { it == currentVideoZoom } + ) { dialog, trackIndex -> + onVideoZoomOptionSelected(videoZoomValues[trackIndex]) + dialog.dismiss() + }.create() + } ?: throw IllegalStateException("Activity cannot be null") + } +} + + +fun VideoZoom.nameRes(): Int { + val stringRes = when (this) { + VideoZoom.BEST_FIT -> R.string.best_fit + VideoZoom.STRETCH -> R.string.stretch + VideoZoom.CROP -> R.string.crop + VideoZoom.HUNDRED_PERCENT -> R.string.hundred_percent + } + + return stringRes +} \ No newline at end of file From e3c80cd7c64f70ba974e249058c08c8ece5bb6b2 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Mon, 14 Aug 2023 11:38:16 +0530 Subject: [PATCH 4/5] lint: run KtlintFormat --- .../dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt | 2 +- .../nextplayer/feature/player/PlayerActivity.kt | 9 ++++----- .../player/dialogs/VideoZoomOptionsDialogFragment.kt | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt index e9234f093..b49b4898e 100644 --- a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt +++ b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/VideoZoom.kt @@ -2,4 +2,4 @@ package dev.anilbeesetti.nextplayer.core.model enum class VideoZoom { BEST_FIT, STRETCH, CROP, HUNDRED_PERCENT -} \ No newline at end of file +} diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index 71483f398..07923c060 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -54,6 +54,7 @@ import dev.anilbeesetti.nextplayer.core.model.DecoderPriority import dev.anilbeesetti.nextplayer.core.model.ScreenOrientation import dev.anilbeesetti.nextplayer.core.model.ThemeConfig import dev.anilbeesetti.nextplayer.core.model.VideoZoom +import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR import dev.anilbeesetti.nextplayer.feature.player.databinding.ActivityPlayerBinding import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedControlsDialogFragment import dev.anilbeesetti.nextplayer.feature.player.dialogs.TrackSelectionDialogFragment @@ -76,13 +77,12 @@ import dev.anilbeesetti.nextplayer.feature.player.utils.PlayerApi import dev.anilbeesetti.nextplayer.feature.player.utils.PlayerGestureHelper import dev.anilbeesetti.nextplayer.feature.player.utils.PlaylistManager import dev.anilbeesetti.nextplayer.feature.player.utils.toMillis +import java.nio.charset.Charset +import java.util.Arrays import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber -import java.nio.charset.Charset -import java.util.Arrays -import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR @SuppressLint("UnsafeOptInUsageError") @AndroidEntryPoint @@ -670,7 +670,6 @@ class PlayerActivity : AppCompatActivity() { } } - private fun applyVideoZoom(videoZoom: VideoZoom) { viewModel.setVideoZoom(videoZoom) when (videoZoom) { @@ -758,4 +757,4 @@ inline fun > T.next(): T { val values = enumValues() val nextOrdinal = (ordinal + 1) % values.size return values[nextOrdinal] -} \ No newline at end of file +} diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt index b276b852a..a601b4f1d 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/dialogs/VideoZoomOptionsDialogFragment.kt @@ -14,7 +14,6 @@ class VideoZoomOptionsDialogFragment( private val onVideoZoomOptionSelected: (videoZoom: VideoZoom) -> Unit ) : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val videoZoomValues = VideoZoom.values() return activity?.let { activity -> @@ -31,7 +30,6 @@ class VideoZoomOptionsDialogFragment( } } - fun VideoZoom.nameRes(): Int { val stringRes = when (this) { VideoZoom.BEST_FIT -> R.string.best_fit @@ -41,4 +39,4 @@ fun VideoZoom.nameRes(): Int { } return stringRes -} \ No newline at end of file +} From 9cab43abb2b4a060de6f50ea6f79ee181f5a7dae Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Mon, 14 Aug 2023 11:46:39 +0530 Subject: [PATCH 5/5] fix: call requestLayout() function after changing width and height --- .../nextplayer/feature/player/PlayerActivity.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index 07923c060..5741119b4 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -670,26 +670,29 @@ class PlayerActivity : AppCompatActivity() { } } + private fun resetExoContentFrameWidthAndHeight() { + exoContentFrameLayout.layoutParams.width = binding.playerView.width + exoContentFrameLayout.layoutParams.height = binding.playerView.height + exoContentFrameLayout.requestLayout() + } + private fun applyVideoZoom(videoZoom: VideoZoom) { viewModel.setVideoZoom(videoZoom) when (videoZoom) { VideoZoom.BEST_FIT -> { - exoContentFrameLayout.layoutParams.width = binding.playerView.width - exoContentFrameLayout.layoutParams.height = binding.playerView.height + resetExoContentFrameWidthAndHeight() binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_fit_screen) } VideoZoom.STRETCH -> { - exoContentFrameLayout.layoutParams.width = binding.playerView.width - exoContentFrameLayout.layoutParams.height = binding.playerView.height + resetExoContentFrameWidthAndHeight() binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_aspect_ratio) } VideoZoom.CROP -> { - exoContentFrameLayout.layoutParams.width = binding.playerView.width - exoContentFrameLayout.layoutParams.height = binding.playerView.height + resetExoContentFrameWidthAndHeight() binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_crop_landscape) } @@ -698,6 +701,7 @@ class PlayerActivity : AppCompatActivity() { currentVideoSize?.let { exoContentFrameLayout.layoutParams.width = it.width exoContentFrameLayout.layoutParams.height = it.height + exoContentFrameLayout.requestLayout() } binding.playerView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT videoZoomButton.setImageDrawable(this, coreUiR.drawable.ic_width_wide)