简体   繁体   English

实现画中画功能时如何解决长宽比问题?

[英]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.

相关问题 画中画-长宽比过高 - Picture In Picture - Aspect ratio is too extreme 如何进一步缩小android画中画窗口的大小? - How to further reduce the size of the android picture-in-picture window? 禁用某些应用的画中画模式 - Disable picture-in-picture mode for some app 是否可以在Android的画中画中运行Camera2? - Is it possible to run Camera2 in Picture-in-Picture in Android? Apache POI Excel工作表:在调整图片大小的同时保持其比例 - Apache POI Excel sheet: resize a picture while keeping its ratio java.lang.IllegalStateException: enterPictureInPictureMode: 当前活动不支持画中画 - java.lang.IllegalStateException: enterPictureInPictureMode: Current activity does not support picture-in-picture Android:以画中画模式播放视频(单击关闭按钮时的多个实例) - Android: playing video in picture-in-picture mode ( multiple instances when click on close button) 如何在保持宽高比的同时调整JFrame的大小? - How do I resize a JFrame while maintaining aspect ratio? 维护宽高比时如何在Appwidget中填充ImageView? - How can I fill an ImageView in an Appwidget while mainiting the aspect ratio? Android:如何在保持纵横比的同时将图像拉伸到屏幕宽度? - Android: How to stretch an image to the screen width while maintaining aspect ratio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM