[Android] Pip: check video dimensions before setting AR
Duncan McNamara
git at videolan.org
Thu Jul 4 05:02:21 UTC 2024
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu Jun 27 15:29:52 2024 +0200| [6d5bcc70a6387dae0e1e4c399c82efcf06382eae] | committer: Duncan McNamara
Pip: check video dimensions before setting AR
With videos with dimensions of 0, the ar will be wrong, and creating the
pip window will throw an exception and go to default PiP.
> https://code.videolan.org/videolan/vlc-android/commit/6d5bcc70a6387dae0e1e4c399c82efcf06382eae
---
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index debd4b2a81..212609e7e4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -821,9 +821,13 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
try {
val track = service?.playlistManager?.player?.mediaplayer?.getSelectedVideoTrack()
?: return
- val ar = Rational(track.getWidth().coerceAtMost((track.getHeight() * 2.39f).toInt()), track.getHeight())
+ val width = track.getWidth()
+ val height = track.getHeight()
+ val paramBuilder = PictureInPictureParams.Builder()
+ if (width != 0 && height != 0 && (width.toFloat() / height.toFloat()) in 0.418410f..2.39f)
+ paramBuilder.setAspectRatio(Rational(width, height))
service?.updateWidgetState()
- enterPictureInPictureMode(PictureInPictureParams.Builder().setAspectRatio(ar).build())
+ enterPictureInPictureMode(paramBuilder.build())
} catch (e: IllegalArgumentException) { // Fallback with default parameters
enterPictureInPictureMode()
}
More information about the Android
mailing list