[英]How to solve aspect ratio issue while implementing Picture-in-picture feature?
I am trying to include a PiP(Picture-in-picture) feature in an app. 我正在尝试在应用程序中包括画中画(PiP)功能。 I am encountering the following error : 我遇到以下错误:
Caused by: java.lang.IllegalArgumentException: enterPictureInPictureMode: Aspect ratio is too extreme (must be between 0.418410 and 2.390000).
I would like to know how do to solve this issue. 我想知道如何解决这个问题。 I have tried different techniques by making changes in xml as well as my java file. 我通过在xml和Java文件中进行更改尝试了不同的技术。 None have helped my issue. 没有人帮助我解决问题。
I am including my java as well as xml code for more clarity : 为了更加清晰,我包括了我的java和xml代码:
Java : Java的:
Rational aspectRatio = new Rational(videoView.getWidth(), videoView.getHeight());
pictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(pictureInPictureParamsBuilder.build());
XML : XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.courses.oustchat.VideoPipActivity">
<VideoView
android:id="@+id/pipvideoview"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_margin="4dp"
android:adjustViewBounds="true"/>
</RelativeLayout>
Pls. PLS。 do provide a solution for this. 确实为此提供了解决方案。
Thanks in advance. 提前致谢。
This error happen because videoView.getWidth and .getheight method gives value more than pip mode support as exception saying the aspect ratio you set is more than pip mode support. 发生此错误的原因是videoView.getWidth和.getheight方法提供的值比pip模式支持更多,因为例外情况是您设置的纵横比大于pip模式支持。 Let's leave it to android by not setting ratio by yourself 让我们不用自己设置比例就将其留给android
pictureInPictureParamsBuilder.build();
enterPictureInPictureMode(pictureInPictureParamsBuilder.build());
or if you want to set custom than do like below but your ratio must be between 0.418410 and 2.390000: 或者,如果您想要设置自定义,而不是像下面这样,但是您的比率必须介于0.418410和2.390000之间:
Rational aspectRatio = new Rational(192, 108);
pictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
enterPictureInPictureMode(pictureInPictureParamsBuilder.build());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.