Android 支持缩放视频吗?
使用VideoView可以为Android设置比例因子吗?默认情况下,视频视图会自行调整大小以适应视频的编码分辨率。我可以强制 Android 将视频渲染为更小或更大的矩形吗?
Using a VideoView is it possible to set a scale factor for Android? By Default the video view resizes itself to fit the encoded resolution of the Video. Can I force Android to render a video into a smaller or larger rect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
(我知道这是一个非常老的问题,但是还有另一种控制尺寸的方法,这里没有描述,也许有人会发现它很有帮助。)
在布局中声明您自己的 MyVideoView 类并编写您的自己的 onMeasure() 方法。以下是如何运行拉伸到原始视图尺寸的视频:
(I know it's very old question, but there is another way to control dimensions, which isn't described here, maybe someone will find it helpful.)
Declare your own MyVideoView class in your layout and write your own onMeasure() method. Here is how to run video stretched to original View's dimensions:
要为
VideoView
设置"centerCrop"
缩放类型,您的onMeasure()
和layout()
方法可能如下所示:To set
"centerCrop"
scale type forVideoView
youronMeasure()
andlayout()
methods may look like this:VideoView
(或与MediaPlayer
一起使用的SurfaceView
)将是您在布局中指定的大小。 在该空间内,视频将尽可能大地播放,同时保持宽高比。是的:将您的
VideoView
设置为您想要的大小,Android 将缩放以适合VideoView
的大小。VideoView
(or theSurfaceView
for use withMediaPlayer
) will be the size you tell it to be in your layout. Within that space, the video will play back as large as possible while maintaining the aspect ratio.Yes: make your
VideoView
be the size you want, and Android will scale to fit the size of theVideoView
.我发现当 VideoView 放置在relativelayout 中时,视频会拉伸高度和宽度以适合 VideoView 指定的高度和宽度(无论视频宽高比如何)。但是,当我将 VideoView 放入 FrameLayout 中时,视频会拉伸高度和宽度,直到它与 VideoView 的指定高度或宽度之一匹配(即,它不会破坏宽高比) )。奇怪,我知道,但这就是我发现的!
I find that when a VideoView is placed inside a RelativeLayout, the video stretches both height and width to fit the VideoView's specified height and width (irrespective of the video aspect ratio). However, when I place the VideoView in a FrameLayout, the video stretches height and width until it matches one of the VideoView's specified height or width (i.e. it does not break aspect ratio). Strange, I know, but that's what I found!
我也在努力实现这一目标,到目前为止效果还不错。这个想法是使用视频视图的 setLayoutParams 并指定大小。这只是一个简单的片段,但它给出了想法。检查 LayoutParams 行。
I am also trying to achieve that and so far this has worked ok. The idea is to use the setLayoutParams for the video view and specify the size. It is just a simple fragment but it gives the idea. Check the LayoutParams lines.
到 FeelGoods 回答。
如果没有layout()方法,“centerCrop”缩放类型更好,但VideoView必须位于FrameLayout中。
To FeelGoods answer.
Without the layout() method the "centerCrop" scale type is better, but the VideoView must be in a FrameLayout.
伙计们,我有其他想法通过扩展 VideoView 创建您自己的 VideoView 类,这样您就可以做任何您想做的事情。确切地说,您必须在 VideoView 中创建几个方法。
为您的 VideoView 类创建您自己的构造函数,并确保您自己的 videoview 类中使用此方法,然后将其像 android 默认 videoview 一样使用到 xml 和类文件中。
希望有帮助。
Guys I had other idea create your own VideoView class by extending VideoView, with that u can do what ever u want,. exactly u have to create couple of methods in your VideoView.
make your own constructor for ur VideoView class and make sure this methods in ur own videoview class then use it as like androids default videoview into both xml and class files.
Hope it helps.