简体   繁体   English

不同屏幕尺寸的 VideoView

[英]VideoView in different screen sizes

I'm trying to insert a video for different sizes of screen.我正在尝试为不同尺寸的屏幕插入视频。 What I want it's a good resolution and without distortion.我想要的是一个很好的分辨率并且没有失真。 I have 2 videos for large and tiny screens.我有 2 个用于大屏幕和小屏幕的视频。 But I don't know how to insert them.但我不知道如何插入它们。

I thought it was like insert images from drawables files (hdpi, ldpi, etc) where you add the image in the resolution folder that you want.我认为这就像从可绘制文件(hdpi、ldpi 等)中插入图像,您可以在其中将图像添加到所需的分辨率文件夹中。 But I dont know if happens the same with videos or not.但我不知道视频是否会发生同样的情况。

Please help me to insert both videos to different resolutions!请帮我将两个视频插入不同的分辨率!

Thanks!谢谢!

A Drawable , as far as Android is concerned is any kind of graphic/image/icon... But a video doesn't fall in that category.就 Android 而言, Drawable是任何类型的图形/图像/图标......但视频不属于该类别。 For that matter, you'll have to place it at the "./assets/" folder.就此而言,您必须将其放在“./assets/”文件夹中。 Therefore, videos aren't automatically selected according to the screen size.因此,不会根据屏幕大小自动选择视频。

However, even if the videos are in a different folder, you can load them programmatically at the onCreate() method, like this:但是,即使视频位于不同的文件夹中,您也可以在 onCreate() 方法中以编程方式加载它们,如下所示:

Display mDisplay = getWindowManager().getDefaultDisplay(); 
int w = mDisplay.getWidth();
int h = mDisplay.getHeight();

if (w < 480 || h < 800) {
    mVideoView.setVideoPath(...your video in assets, of low resolution...);;
} else {
    mVideoView.setVideoPath(...your video in assets, of high resolution...);
}
...

With this or a similar method, you can load different videos, according to the user resolution, in a way that is even more precise than the ldpi/mdpi/etc method.使用这种或类似的方法,您可以根据用户分辨率以比 ldpi/mdpi/etc 方法更精确的方式加载不同的视频。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM